我需要使用 fractur 字体定义计数器和希伯来语字母表。对于希腊字母表,我使用包恩格莱克。有什么建议吗?谢谢
答案1
约翰·科米洛 (John Kormylo) 可能意味着是,如果列举所有可能发生的情况是合理的,那么您可以解释\alph
LaTeX 中的定义,它依赖于 TeX 的\ifcase
条件,如下所示:
\def\alph#1{\expandafter\@alph\csname c@#1\endcsname}
\def\@alph#1{%
\ifcase#1\or a\or b\or c\or d\or e\or f\or g\or h\or i\or j\or
k\or l\or m\or n\or o\or p\or q\or r\or s\or t\or u\or v\or w\or x\or
y\or z\else\@ctrerr\fi}
例如,以下是使用著名的(?)格式化 LaTeX 计数器的一种愚蠢方法沙多克数字系统。这是一个以 4 为基数的数字系统,其中每个数字的可用符号为 Ga = 0、Bu = 1、Zo = 2 和 Meu = 3。
\documentclass{article}
\usepackage{pgffor} % only for the demo code
\usepackage{multicol} % only for the demo code
\makeatletter
\newcommand*{\@shadokNumber}[1]{%
\ifcase #1% #1 is supposed to be a <number>
Ga\or Bu\or Zo\or Meu\or
BuGa\or BuBu\or BuZo\or BuMeu\or
ZoGa\or ZoBu\or ZoZo\or ZoMeu\or
MeuGa\or MeuBu\or MeuZo\or MeuMeu\or
BuGaGa\or BuGaBu\or BuGaZo\or BuGaMeu\or
BuBuGa\or BuBuBu\or BuBuZo\or BuBuMeu\or
BuZoGa\or BuZoBu\or BuZoZo\or BuZoMeu\or
BuMeuGa\or BuMeuBu\or BuMeuZo\or BuMeuMeu\or
ZoGaGa\or ZoGaBu\or ZoGaZo\or ZoGaMeu\or
ZoBuGa\or ZoBuBu\or ZoBuZo\or ZoBuMeu\or
ZoZoGa\or ZoZoBu\or ZoZoZo\or ZoZoMeu\or
ZoMeuGa\or ZoMeuBu\or ZoMeuZo\or ZoMeuMeu\or
MeuGaGa\or MeuGaBu\or MeuGaZo\or MeuGaMeu\or
MeuBuGa\or MeuBuBu\or MeuBuZo\or MeuBuMeu\or
MeuZoGa\or MeuZoBu\or MeuZoZo\or MeuZoMeu\or
MeuMeuGa\or MeuMeuBu\or MeuMeuZo\or MeuMeuMeu\or BuGaGaGa% = 64 in decimal
% etc.
\else \@ctrerr \fi
}
\newcommand*{\shadokNumber}[1]{%
\expandafter\@shadokNumber\csname c@#1\endcsname
}
\makeatother
\newcounter{myctr}
\begin{document}
\begin{multicols}{3}
\noindent
\foreach \i in {0,...,64} {%
\shadokNumber{myctr}\\
\stepcounter{myctr}%
}%
etc.
\end{multicols}
\end{document}
概括(位置数字系统)
常规位置数字系统可以用通用代码处理。以下内容借鉴了 的实现expl3
并对其进行了改编,\int_to_base:nn
以便提供 Shadok 数字系统中任意整数的格式。这里可用的数字符号仍然是Ga
、Bu
和(每个都有几个标记),但您可以用您选择的任何 LaTeX 代码替换它们。只是不要忘记更新 中的可用符号数量(此处:4)。Zo
Meu
\g_guidone_nb_symbols_int
\documentclass{article}
\usepackage{expl3}
\usepackage{multicol} % only for the demo code
\ExplSyntaxOn
% Ga, Bu, Zo, Meu: 4 symbols. Replace with the number of digit symbols you have.
\int_const:Nn \c_guidone_nb_shadok_digit_symbols_int { 4 }
% Replace Ga, Bu, Zo, Meu with LaTeX code producing each possible digit symbol.
\cs_new:Npn \__guidone_to_shadok_digit:n #1
{
\exp_after:wN \__guidone_remove_fi:nw
\if_case:w #1 \c_space_token % this finishes the <number>
{ Ga }
\or:
{ Bu }
\or:
{ Zo }
\or:
{ Meu }
\else:
{ \msg_expandable_error:nnn { guidone } { too-large-for-a-digit } {#1} }
\fi:
}
\msg_new:nnn { guidone } { too-large-for-a-digit }
{ Too~large~for~a~digit:~\exp_not:n {#1}. }
% Define aliases that can be used outside \ExplSyntaxOn ... \ExplSyntaxOff.
\cs_new_eq:NN \nbShadokDigitSymbols \c_guidone_nb_shadok_digit_symbols_int
\cs_new_eq:NN \toShadokDigit \__guidone_to_shadok_digit:n
% The \exp_stop_f: stops f-expansion from the \__guidone_deliver:nfw call.
% \__guidone_to_digit:n should normally be used within f-expansion,
% otherwise the \exp_stop_f: (implicit space token) will precede the wanted
% result (digit).
\cs_new:Npn \__guidone_remove_fi:nw #1#2\fi:
{ \fi: \exp_stop_f: #1 }
% #1: base (= number of available digit symbols)
% #2: function such as \__guidone_to_shadok_digit:n (input: a number between 0
% and #1 - 1, both inclusive; output: a single digit)
% #3: number to format
\cs_new:Npn \guidone_format_number:nNn #1#2#3
{
\exp:w
\__guidone_to_base:nnN {#3} {#1} #2
\q_stop
}
% The \*_to_base:* functions are based on code from l3int.dtx, with
% modifications so that \guidone_format_number:nNn can deliver potentially
% sensitive material with \exp_not:n in exactly two expansion steps.
\cs_new:Npn \__guidone_to_base:nnN #1
{ \exp_args:Nf \__guidone_to_base_aux:nnN { \int_eval:n {#1} } }
\cs_new:Npn \__guidone_to_base_aux:nnN #1#2#3
{
\int_compare:nNnTF {#1} < { 0 }
{ \exp_args:No \__guidone_to_base:nnnN { \use_none:n #1 } {#2} { - } #3 }
{ \__guidone_to_base:nnnN {#1} {#2} { } #3 }
}
% #1: empty or minus sign
% #2: leftmost digit of the number (i.e., the last digit produced by
% \guidone_format_number:nNn)
% #3: the remaining digits
%
% The \exp_end: terminates the expansion started by \exp:w in
% \guidone_format_number:nNn.
\cs_new:Npn \__guidone_deliver:nnw #1#2#3\q_stop
{ \exp_end: \exp_not:n { #1#2#3 } }
\cs_generate_variant:Nn \__guidone_deliver:nnw { nf }
\cs_new:Npn \__guidone_to_base:nnnN #1#2#3#4
{
\int_compare:nNnTF {#1} < {#2}
{ \__guidone_deliver:nfw {#3} { #4 {#1} } }
{
\exp_args:Nf \__guidone_to_base:nnnnN
{ #4 { \int_mod:nn {#1} {#2} } }
{#1}
{#2}
{#3}
#4
}
}
\cs_new:Npn \__guidone_to_base:nnnnN #1#2#3#4#5
{
\exp_args:Nf \__guidone_to_base:nnnN
{ \int_div_truncate:nn {#2} {#3} }
{#3}
{#4}
#5
#1
}
% Define aliases that can be used outside \ExplSyntaxOn ... \ExplSyntaxOff.
% Note that \guideoneFormatNumber is fully expandable and delivers the result
% in two expansion steps.
\cs_new_eq:NN \guideoneFormatNumber \guidone_format_number:nNn
\cs_new_eq:NN \intstepinline \int_step_inline:nnnn
\ExplSyntaxOff
% What follows \shadokNumber in the input stream will be the third argument of
% \guideoneFormatNumber, i.e.: the number to convert.
\newcommand*{\shadokNumber}{%
\guideoneFormatNumber{\nbShadokDigitSymbols}{\toShadokDigit}%
}
\newcounter{myctr}
% Make it so that \themyctr uses our custom numeration style.
\renewcommand{\themyctr}{%
\shadokNumber{\value{myctr}}%
}
\begin{document}
\begin{multicols}{3}
\noindent
% Initial value, step, final value
\intstepinline{0}{1}{64}{%
\themyctr\\
\stepcounter{myctr}%
}%
etc.
\end{multicols}
Most importantly:
\[ 65536 = \shadokNumber{65536} \]
and % We can handle any 〈integer expression〉, including negative ones.
\[ -(3\times 64 + 2\times 16 + 1\times 4 + 0\times 1) =
\shadokNumber{-1*(3*64 + 2*16 + 1*4 + 0*1)} \]
% Verify that the desired result is obtained in exactly two expansion steps.
% If you uncomment the following seven lines, TeX will print on the terminal:
% > \exp_not:n {-MeuZoBuGa}.
%
% \def\zzz#1{\expandafter\showtokens\expandafter{#1}}
% \expandafter\zzz\expandafter{%
% \guideoneFormatNumber
% {\nbShadokDigitSymbols}
% {\toShadokDigit}
% {-1*(3*64 + 2*16 + 1*4 + 0*1)}%
% }
\end{document}
从以下定义可以看出:
\newcommand*{\shadokNumber}{%
\guideoneFormatNumber{\nbShadokDigitSymbols}{\toShadokDigit}%
}
为了在同一文档中定义其他数字系统的转换函数,您唯一需要做的就是传递\guideoneFormatNumber
:
可用数字符号的数量,即根据(
\nbShadokDigitSymbols
在我们的例子中为 4);一个函数,例如
\toShadokDigit
(即\__guidone_to_shadok_digit:n
),将数字在 0 和根据- 1 为目标数字系统中的 1 位表示形式。
要转换的数字必须位于输入流的下一个位置,并且不需要作为参数来抓取\shadokNumber
(这是一个小的优化)。
希伯来数字
希伯来数字似乎没有上述代码设计的那样规则。如果只需要少量值,则可以使用第一种方法。否则,恐怕您需要另一种转换算法。该polyglossia
包提供了诸如 和 之类的命令\hebrewnumeral
,\Hebrewnumeral
这些\Hebrewnumeralfinal
命令可能会引起您的兴趣。您可能对以下内容感兴趣这个问题例如。唉,我不懂希伯来语,所以在这方面不能给你更多帮助。
答案2
刚刚发布的 3.41 版本基于babel
CSS,为一些语言提供了一组预定义的加法和字母数字现成的柜台风格(数字样式自 3.20 开始可用babel
)。更重要的是,它们是在文件中的一组键/值对的帮助下定义的ini
,这意味着您也可以使用 定义自己的样式\babelprovide
。注意,此工具适用于xetex
和luatex
,但它可能工作pdftex
。下面是带有一些解释的示例。
\documentclass{article}
\usepackage[italian]{babel}
\babelprovide[
% To define a purely alphabetic numeral, just provide a space-
% separated list of ordered symbols, characters, etc. Let's name
% it 'lower' (you can choose another name):
counters/lower=Aa Bb Cc Dd Ee Ff Gg Hh Ii Jj Kk Ll,
% For additive numerals, a set of four keys are required, numbered
% with a digit from 1 (for 1-9) to 4 (for 1000-9000) preceded by a
% dot. Let's name it 'letters':
counters/letters.1= a b c d e f g h i,
counters/letters.2= k l m n o p q r s,
counters/letters.3= A B C D E F G H I,
counters/letters.4= K L M N O P Q R S,
% Fixed representations for specific values of additive numerals
% are allowed, too. Just end the key with dot, uppercase F, dot,
% number:
counters/letters.F.55 = Oohh
% Redefining \alph to print these numerals is simple:
alph = letters
]{italian}
\begin{document}
\localenumeral{lower}{4} % Prints Dd
\localenumeral{lower}{2} % Prints Bb
\localenumeral{letters}{956} % Prints Iof
\localenumeral{letters}{55} % Prints Oohh
\alph{page} % Prints a, because it's the first page and \alph uses the
% 'letters' numerals
\end{document}
有关详细信息,请参阅babel 3.41 中的新功能。