| 1 |
%GregorioTeX common file (stuff needed by both gregoriotex and gregoriosyms) |
| 2 |
% |
| 3 |
% Copyright (C) 2007-2025 The Gregorio Project (see CONTRIBUTORS.md) |
| 4 |
% |
| 5 |
% This file is part of Gregorio. |
| 6 |
% |
| 7 |
% Gregorio is free software: you can redistribute it and/or modify |
| 8 |
% it under the terms of the GNU General Public License as published by |
| 9 |
% the Free Software Foundation, either version 3 of the License, or |
| 10 |
% (at your option) any later version. |
| 11 |
% |
| 12 |
% Gregorio is distributed in the hope that it will be useful, |
| 13 |
% but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
% GNU General Public License for more details. |
| 16 |
% |
| 17 |
% You should have received a copy of the GNU General Public License |
| 18 |
% along with Gregorio. If not, see <http://www.gnu.org/licenses/>. |
| 19 |
|
| 20 |
\gre@declarefileversion{gregoriotex-common.tex}{6.1.0}% GREGORIO_VERSION |
| 21 |
|
| 22 |
\ifnum\luatexversion<76% |
| 23 |
\gre@error{Error: this document must be compiled with LuaTeX (lualatex) 0.76 or later}% |
| 24 |
\fi% |
| 25 |
|
| 26 |
% Run a command for each string in a comma-separated list of strings. |
| 27 |
% #1: a comma-separated list of strings |
| 28 |
% #2: a command |
| 29 |
% Examples: |
| 30 |
% \greparsecommas{}{\typeout} does nothing. |
| 31 |
% \greparsecommas{foo}{\typeout} -> \typeout{foo} |
| 32 |
% \greparsecommas{foo,bar}{\typeout} -> \typeout{foo}\typeout{bar} |
| 33 |
% Note: Does not strip out any whitespace. |
| 34 |
\newcount\gre@count@parsecommas@cur |
| 35 |
\def\gre@parsecommas#1#2{% |
| 36 |
% https://tex.stackexchange.com/a/510410 |
| 37 |
\def\gre@parsecommas@options{,#1,}% |
| 38 |
\gre@debugmsg{parsecommas}{\gre@parsecommas@options}% |
| 39 |
\IfStrEq{\gre@parsecommas@options}{,,}{% |
| 40 |
% do nothing |
| 41 |
}{% |
| 42 |
\StrCount{\gre@parsecommas@options}{,}[\gre@parsecommas@total]% number of items plus one |
| 43 |
\gre@count@parsecommas@cur=1\relax |
| 44 |
\loop\ifnum\gre@count@parsecommas@cur<\gre@parsecommas@total\relax |
| 45 |
\StrBetween[\the\gre@count@parsecommas@cur,\the\numexpr\gre@count@parsecommas@cur+1]{\gre@parsecommas@options}{,}{,}[\gre@parsecommas@option]% |
| 46 |
#2{\gre@parsecommas@option}% |
| 47 |
\advance\gre@count@parsecommas@cur by 1\relax |
| 48 |
\repeat |
| 49 |
}% |
| 50 |
} |
| 51 |
|
| 52 |
%%%%%%%%% |
| 53 |
%% Debugging |
| 54 |
%%%%%%%%% |
| 55 |
|
| 56 |
\def\gre@debugmsg#1#2{% |
| 57 |
\IfStrEq{\gre@debug}{}{}% |
| 58 |
%false |
| 59 |
{\IfStrEq{#1}{all}% |
| 60 |
%true |
| 61 |
{\gre@error{Debug error: ‘all’ is not a permitted keyword}}% |
| 62 |
%false |
| 63 |
{\IfStrEq{\gre@debug}{,all,}% |
| 64 |
%true |
| 65 |
{\gre@typeout{GregorioTeX debug: (#1) #2}}% |
| 66 |
%false |
| 67 |
{\IfSubStr{\gre@debug}{,#1,}% |
| 68 |
%true |
| 69 |
{\gre@typeout{GregorioTeX debug: (#1) #2}}% |
| 70 |
%false |
| 71 |
{\relax}% |
| 72 |
}% |
| 73 |
}% |
| 74 |
}% |
| 75 |
}% |
| 76 |
|
| 77 |
\def\gre@fixdebug{% |
| 78 |
{% we're starting a group in order to localize \exploregroups |
| 79 |
\exploregroups% |
| 80 |
\StrRemoveBraces{\gre@debug}[\gre@debug]% |
| 81 |
\xdef\gre@debug{,\gre@debug,}% |
| 82 |
}% |
| 83 |
}% |
| 84 |
|
| 85 |
\IfStrEq{\gre@debug}{}{% then |
| 86 |
}{% else |
| 87 |
\typeout{GregorioTeX is in debug mode}% |
| 88 |
\typeout{\gre@debug\space messages will be printed to the log.}% |
| 89 |
\gre@fixdebug\relax % |
| 90 |
}% |
| 91 |
|
| 92 |
%%%%%%%%%%%%% |
| 93 |
% Macros to handle deprecation path. |
| 94 |
%%%%%%%%%%%%% |
| 95 |
|
| 96 |
% #1 - the deprecated macro |
| 97 |
% #2 - the correct macro to use |
| 98 |
\def\gre@deprecated#1#2{% |
| 99 |
\ifgre@allowdeprecated% |
| 100 |
\ifx&% |
| 101 |
\gre@warning{#1\space is deprecated and marked for removal}% |
| 102 |
\else% |
| 103 |
\gre@warning{#1\space is deprecated.\MessageBreak Use #2\space instead}% |
| 104 |
\fi% |
| 105 |
\else% |
| 106 |
\ifx&% |
| 107 |
\gre@error{#1\space is deprecated and marked for removal}% |
| 108 |
\else% |
| 109 |
\gre@error{#1\space is deprecated.\MessageBreak Use #2\space instead}% |
| 110 |
\fi% |
| 111 |
\fi% |
| 112 |
\relax% |
| 113 |
}% |
| 114 |
|
| 115 |
\def\gre@obsolete#1#2{% |
| 116 |
\ifx&% |
| 117 |
\gre@error{#1\space is obsolete and no longer has any effect}% |
| 118 |
\else% |
| 119 |
\gre@error{#1\space is obsolete.\MessageBreak Use #2\space instead}% |
| 120 |
\fi% |
| 121 |
\relax% |
| 122 |
}% |
| 123 |
|
| 124 |
%%%%%%%%%%%%% |
| 125 |
% Internal function tracing |
| 126 |
%%%%%%%%%%%%% |
| 127 |
|
| 128 |
% Each function in the internal name space (\gre@...) should have an invocation of |
| 129 |
% \gre@trace as its first line with the argument being the name of the function (without |
| 130 |
% the backslash) and the list of arguments. |
| 131 |
% The last line of these functions should be \gre@trace@end. |
| 132 |
% Macros which merely store a value are not considered to be functions and thus not |
| 133 |
% included in the trace stack. |
| 134 |
% We also exempt the internal aliases for functions defined elsewhere. |
| 135 |
% The tracing messages are turned on via the debug interface, keyword: trace. |
| 136 |
|
| 137 |
\def\gre@trace@prefix{GreTrace: } |
| 138 |
\def\gre@trace#1{% |
| 139 |
\IfSubStr{\gre@debug}{,trace,}% |
| 140 |
{%print tracing messages and increase indent |
| 141 |
\gre@typeout{\gre@trace@prefix \unexpanded{#1}}% |
| 142 |
\edef\gre@trace@prefix{\gre@trace@prefix| }% |
| 143 |
}{}%do nothing if not tracing |
| 144 |
}% |
| 145 |
\def\gre@trace@end{% |
| 146 |
\IfSubStr{\gre@debug}{,trace,}% |
| 147 |
{%dedent trace messages and mark end |
| 148 |
\StrGobbleRight{\gre@trace@prefix}{2}[\gre@trace@prefix]% |
| 149 |
\gre@typeout{\gre@trace@prefix -----}% |
| 150 |
}{}%do nothing if not tracing |
| 151 |
} |
| 152 |
|