TeX - LaTeX Asked on January 12, 2021
How do I make item
labels to be computed modulo 4 (to see it on a small example) .
Then I change it to modulo 1000 in my final project.
documentclass{article}
usepackage[no-math]{fontspec}
newfontfamilyngg{Segoe UI Historic}[Ligatures=TeX]
usepackage{enumitem}
begin{document}
begin{enumerate}[ label=largenggsymbol{numexpr "13000+value{enumi}}]
item this label should be {nggsymbol{"13001}} and is such
item this label should be {nggsymbol{"13002}} and is such
item this label should be {nggsymbol{"13003}} and is such
item this label should be {nggsymbol{"13001}} but is {nggsymbol{"13004}}
item this label should be {nggsymbol{"13002}} but is {nggsymbol{"13005}}
item this label should be {nggsymbol{"13003}} but is {nggsymbol{"13006}}
item this label should be {nggsymbol{"13001}} but is {nggsymbol{"13007}}
item etc. 13000+i modulo 4
end{enumerate}
end{document}
I apologize for a small typo (in my intended modulo 4 operation) but the idea
should be clear.
Here an example that can grow. But I didn't check if your font has 1000 consecutive glyphs starting from 13000, so it is quite possible that you will get missings glyphs somewhere in the middle:
documentclass{article}
usepackage[no-math]{fontspec}
newfontfamilyngg{Segoe UI Historic}[Ligatures=TeX]
usepackage{enumitem}
ExplSyntaxOnmakeatletter
cs_new_protected:Npn @moduloitem #1
{
ngg
char
int_eval:n
{
int_mod:nn{int_use:c{#1}}{modulolength}
+
exp_args:Noint_from_hex:n{modulostart}
}
}
newcommandmoduloitem[1]{@moduloitem{c@#1}}
newcommandmodulostart{13000} %adapt
newcommandmodulolength{3} %adapt
AddEnumerateCounter{moduloitem}{@moduloitem}{AA}
ExplSyntaxOffmakeatother
begin{document}
begin{enumerate}[ label=moduloitem*]
item this label should be {nggsymbol{"13001}} and is such
item this label should be {nggsymbol{"13002}} and is such
item this label should be {nggsymbol{"13003}} and is such
item this label should be {nggsymbol{"13001}} but is {nggsymbol{"13004}}
item this label should be {nggsymbol{"13002}} but is {nggsymbol{"13005}}
item this label should be {nggsymbol{"13003}} but is {nggsymbol{"13006}}
item this label should be {nggsymbol{"13001}} but is {nggsymbol{"13007}}
item etc. 13000+i modulo 4
end{enumerate}
end{document}
Correct answer by Ulrike Fischer on January 12, 2021
Firstly, by your example, what you want is modulo 3, not 4. Here is an example making use of enumitem
's AddEnumerateCounter
.
documentclass{article}
usepackage[no-math]{fontspec}
newfontfamilyngg{Segoe UI Historic}[Ligatures=TeX]
usepackage{enumitem}
makeatletter
defhistoricCnt#1{expandafter@historicCntcsname c@#1endcsname}
def@historicCnt#1{%
ifcase#10or1or2or3%
else
expandafter@historicCntexpandafter{numexpr#1-3relax}%
fi
}
AddEnumerateCounter{historicCnt}{@historicCnt}{XX}
makeatother
begin{document}
begin{enumerate}[label=largenggsymbol{numexpr "13000+historicCnt*relax}]
item this label should be {nggsymbol{"13001}} and is such
item this label should be {nggsymbol{"13002}} and is such
item this label should be {nggsymbol{"13003}} and is such
item this label should be {nggsymbol{"13001}} but is {nggsymbol{"13004}}
item this label should be {nggsymbol{"13002}} but is {nggsymbol{"13005}}
item this label should be {nggsymbol{"13003}} but is {nggsymbol{"13006}}
item this label should be {nggsymbol{"13001}} but is {nggsymbol{"13007}}
item etc. 13000+i modulo 4
end{enumerate}
end{document}
A new latex3 flavored function iten_mod:nn
is defined, it accepts two integers #1
and #2
, and returns #1 mod #2
if (#1 mod #2) > 0
, otherwise #2
. You can use it to accomplish "mod 1000" or similar tasks.
documentclass{article}
usepackage{enumitem}
usepackage[no-math]{fontspec}
newfontfamilyngg{Segoe UI Historic}[Ligatures=TeX]
makeatletter
ExplSyntaxOn
% register historicCnt as a new counter representation
AddEnumerateCounter{historicCnt}{@historicCnt}{XX}
% define historicCnt
defhistoricCnt#1{
expandafter@historicCntcsname c@#1endcsname
}
def@historicCnt#1{
item_mod:nn {#1}{3}
}
% return (#1 mod #2) if (#1 mod #2) > 0 else #2
cs_new:Nn item_mod:nn
{
1 + int_mod:nn {#1-1}{#2}
}
makeatother
ExplSyntaxOff
begin{document}
begin{enumerate}[label=largenggsymbol{numexpr "13000+historicCnt*relax}]
item this label should be {nggsymbol{"13001}} and is such
item this label should be {nggsymbol{"13002}} and is such
item this label should be {nggsymbol{"13003}} and is such
item this label should be {nggsymbol{"13001}} but is {nggsymbol{"13004}}
item this label should be {nggsymbol{"13002}} but is {nggsymbol{"13005}}
item this label should be {nggsymbol{"13003}} but is {nggsymbol{"13006}}
item this label should be {nggsymbol{"13001}} but is {nggsymbol{"13007}}
item etc. 13000+i modulo 3
end{enumerate}
end{document}
Answered by muzimuzhi Z on January 12, 2021
Hook properly in enumitem
. I used modulo 3, which is what you actually have in your example.
documentclass{article}
usepackage[no-math]{fontspec}
newfontfamilyngg{SegoeUIHistoric.ttf}[Ligatures=TeX,Scale=1.2]
usepackage{enumitem,xparse}
ExplSyntaxOn
NewDocumentCommand{nggcounter}{m}
{
group_begin:
ngg
symbol
{
int_eval:n { "13001 + int_mod:nn { value{#1} - 1 } { 3 } } % change here the modulus
}
group_end:
}
ExplSyntaxOff
makeatletter
newcommand{@nggcounter}[1]{#1}
AddEnumerateCounter{nggcounter}{@nggcounter}{{nggsymbol{"13001}}}
makeatother
begin{document}
begin{enumerate}[label=nggcounter*]
item this label should be {nggsymbol{"13001}}
item this label should be {nggsymbol{"13002}}
item this label should be {nggsymbol{"13003}}
item this label should be {nggsymbol{"13001}}
item this label should be {nggsymbol{"13002}}
item this label should be {nggsymbol{"13003}}
item this label should be {nggsymbol{"13001}}
item etc. 13000+i modulo 3
end{enumerate}
end{document}
Answered by egreg on January 12, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP