Debian Codegraph @

texk/gregorio/gregorio-src/tex/gregoriotex-symbols.lua

raw symbols SCIP
1 --GregorioTeX Symbols Lua support file.
2 --
3 --Copyright (C) 2016-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 -- this file contains lua functions to support signs used by GregorioTeX.
21
22 -- GREGORIO_VERSION 6.1.0
23
24 local err = gregoriotex.module.err
25 local warn = gregoriotex.module.warn
26 local info = gregoriotex.module.info
27 local log = gregoriotex.module.log
28
29 local catcode_at_letter = luatexbase.catcodetables['gre@atletter']
30 local number_to_letter = gregoriotex.number_to_letter
31 local special_characters = {}
32 local next_special = 0
33
34 function gregoriotex.define_special_character(sequence)
35 local substitution = special_characters[sequence]
36 if substitution == nil then
37 substitution = string.gsub(tostring(next_special), '[0-9]', number_to_letter)
38 special_characters[sequence] = substitution
39 next_special = next_special + 1
40 end
41 tex.print(catcode_at_letter,
42 string.format([[\gdef\gre@special@%s]], substitution))
43 end
44
45 function gregoriotex.undefine_special_character(sequence)
46 local substitution = special_characters[sequence]
47 if substitution ~= nil then
48 special_characters[sequence] = nil
49 tex.print(catcode_at_letter,
50 string.format([[\let\gre@special@%s\undefined\relax ]], substitution))
51 end
52 end
53
54 function gregoriotex.special_character(sequence)
55 local substitution = special_characters[sequence]
56 if substitution ~= nil then
57 tex.print(catcode_at_letter, string.format([[\gre@special@%s\relax ]], substitution))
58 else
59 tex.print(sequence)
60 end
61 end