如何使 `\item` 标签按模 4 计算(查看一个小例子)

如何使 `\item` 标签按模 4 计算(查看一个小例子)

如何使\item标签以模 4 计算(在一个小示例中查看)。然后我在最终项目中将其更改为模 1000。

\documentclass{article}

\usepackage[no-math]{fontspec}
 
\newfontfamily\ngg{Segoe UI Historic}[Ligatures=TeX]
 
\usepackage{enumitem}
\begin{document}
\begin{enumerate}[ label=\large\ngg\symbol{\numexpr "13000+\value{enumi}}]

\item this label should be {\ngg\symbol{"13001}} and is such
\item this label should be {\ngg\symbol{"13002}} and is such
\item this label should be {\ngg\symbol{"13003}} and is such
\item this label should be {\ngg\symbol{"13001}} but is {\ngg\symbol{"13004}}
\item this label should be {\ngg\symbol{"13002}} but is {\ngg\symbol{"13005}}
\item this label should be {\ngg\symbol{"13003}} but is {\ngg\symbol{"13006}}
\item this label should be {\ngg\symbol{"13001}} but is {\ngg\symbol{"13007}}
\item etc. 13000+i modulo 4
\end{enumerate}
\end{document}

我为一个小的打字错误(在我预期的模 4 运算中)表示抱歉,但这个想法应该很清楚。

在此处输入图片描述

答案1

这里有一个可以增长的示例。但我没有检查你的字体是否有从 13000 开始的 1000 个连续的字形,因此你很可能会在中间某处得到缺失的字形:

\documentclass{article}

\usepackage[no-math]{fontspec}

\newfontfamily\ngg{Segoe UI Historic}[Ligatures=TeX]

\usepackage{enumitem}
\ExplSyntaxOn\makeatletter
\cs_new_protected:Npn \@moduloitem #1
  {
   \ngg
    \char
     \int_eval:n
      {
        \int_mod:nn{\int_use:c{#1}}{\modulolength}
        +
        \exp_args:No\int_from_hex:n{\modulostart}
      }
  }
\newcommand\moduloitem[1]{\@moduloitem{c@#1}}  
\newcommand\modulostart{13000}   %adapt
\newcommand\modulolength{3}      %adapt
\AddEnumerateCounter{\moduloitem}{\@moduloitem}{AA}
\ExplSyntaxOff\makeatother
\begin{document}
\begin{enumerate}[ label=\moduloitem*]

\item this label should be {\ngg\symbol{"13001}} and is such
\item this label should be {\ngg\symbol{"13002}} and is such
\item this label should be {\ngg\symbol{"13003}} and is such
\item this label should be {\ngg\symbol{"13001}} but is {\ngg\symbol{"13004}}
\item this label should be {\ngg\symbol{"13002}} but is {\ngg\symbol{"13005}}
\item this label should be {\ngg\symbol{"13003}} but is {\ngg\symbol{"13006}}
\item this label should be {\ngg\symbol{"13001}} but is {\ngg\symbol{"13007}}
\item etc. 13000+i modulo 4
\end{enumerate}
\end{document}

答案2

首先,通过你的例子,你想要的是模3,而不是4。这是一个利用的enumitem例子\AddEnumerateCounter

\documentclass{article}

\usepackage[no-math]{fontspec}

\newfontfamily\ngg{Segoe UI Historic}[Ligatures=TeX]
 
\usepackage{enumitem}
\makeatletter
\def\historicCnt#1{\expandafter\@historicCnt\csname c@#1\endcsname}
\def\@historicCnt#1{%
  \ifcase#10\or1\or2\or3%
  \else
    \expandafter\@historicCnt\expandafter{\numexpr#1-3\relax}%
  \fi
}

\AddEnumerateCounter{\historicCnt}{\@historicCnt}{XX}
\makeatother


\begin{document}
\begin{enumerate}[label=\large\ngg\symbol{\numexpr "13000+\historicCnt*\relax}]

\item this label should be {\ngg\symbol{"13001}} and is such
\item this label should be {\ngg\symbol{"13002}} and is such
\item this label should be {\ngg\symbol{"13003}} and is such
\item this label should be {\ngg\symbol{"13001}} but is {\ngg\symbol{"13004}}
\item this label should be {\ngg\symbol{"13002}} but is {\ngg\symbol{"13005}}
\item this label should be {\ngg\symbol{"13003}} but is {\ngg\symbol{"13006}}
\item this label should be {\ngg\symbol{"13001}} but is {\ngg\symbol{"13007}}
\item etc. 13000+i modulo 4
\end{enumerate}
\end{document}

在此处输入图片描述

更新

\iten_mod:nn定义了一个新的 latex3 函数,它接受两个整数#1和,如果则#2返回,否则返回。您可以使用它来完成“mod 1000”或类似的任务。#1 mod #2(#1 mod #2) > 0#2

\documentclass{article}
\usepackage{enumitem}
\usepackage[no-math]{fontspec}

\newfontfamily\ngg{Segoe UI Historic}[Ligatures=TeX]


\makeatletter
\ExplSyntaxOn

% register \historicCnt as a new counter representation
\AddEnumerateCounter{\historicCnt}{\@historicCnt}{XX}

% define \historicCnt
\def\historicCnt#1{
  \expandafter\@historicCnt\csname c@#1\endcsname
}

\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=\large\ngg\symbol{\numexpr "13000+\historicCnt*\relax}]

\item this label should be {\ngg\symbol{"13001}} and is such
\item this label should be {\ngg\symbol{"13002}} and is such
\item this label should be {\ngg\symbol{"13003}} and is such
\item this label should be {\ngg\symbol{"13001}} but is {\ngg\symbol{"13004}}
\item this label should be {\ngg\symbol{"13002}} but is {\ngg\symbol{"13005}}
\item this label should be {\ngg\symbol{"13003}} but is {\ngg\symbol{"13006}}
\item this label should be {\ngg\symbol{"13001}} but is {\ngg\symbol{"13007}}
\item etc. 13000+i modulo 3
\end{enumerate}

\end{document}

答案3

正确挂钩enumitem。我使用了模 3,这正是您的示例中实际所用的。

\documentclass{article}

\usepackage[no-math]{fontspec}
 
\newfontfamily\ngg{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}{{\ngg\symbol{"13001}}}
\makeatother

\begin{document}

\begin{enumerate}[label=\nggcounter*]

\item this label should be {\ngg\symbol{"13001}}
\item this label should be {\ngg\symbol{"13002}}
\item this label should be {\ngg\symbol{"13003}}
\item this label should be {\ngg\symbol{"13001}}
\item this label should be {\ngg\symbol{"13002}}
\item this label should be {\ngg\symbol{"13003}}
\item this label should be {\ngg\symbol{"13001}}
\item etc. 13000+i modulo 3

\end{enumerate}

\end{document}

在此处输入图片描述

相关内容