ConTeXt 中的变量名可以包含数字和小数吗?

ConTeXt 中的变量名可以包含数字和小数吗?

我正在编写一份需要通篇显示通用核心标准的文档。通用核心标准都有一个缩写代码,例如“RL.3.1”,用于参考目的。

为了节省每次出现标准时输入的时间,我尝试使用\def来定义一个变量,然后稍后调用它。即使变量名中有数字和小数点,它仍然可以编译。我认为变量名中禁止使用数字和小数,至少在 LaTeX 中是这样。

\def\rl.3.1{RL.3.1: Ask and answer questions to demonstrate understanding of a text, referring explicitly to the text as the basis for the answers.}

\starttext

    \rl.3.1

\stoptext

ConTeXt 中的变量名允许使用数字和小数吗?

答案1

命令名称中只允许使用字母(使用 MkIV 您还可以使用中文或阿拉伯字母),但您可以使用其他方法来获取索引字符串。

第一种方法是\setvalue创建带有数字的命令,然后使用 访问它们\getvalue

\setvalue{RL.3.1}{Ask and answer questions to demonstrate understanding of
                  a text, referring explicitly to the text as the basis for
                  the answers.}

\setvalue{RL.3.2}{Recount stories, including fables, folktales, and myths
                  from diverse cultures; determine the central message,
                  lesson, or moral and explain how it is conveyed through key
                  details in the text.}

\setvalue{RL.3.2}{Describe characters in a story (e.g., their traits,
                  motivations, or feelings) and explain how their actions
                  contribute to the sequence of events.}

\starttext
\getvalue{RL.3.1}
\stoptext

另一种方法是\setvariables使用命令为每个键设置一个文本。然后可以使用 访问这些文本\getvariable

\setvariables [RL]
  [3.1={Ask and answer questions to demonstrate understanding of a text,
        referring explicitly to the text as the basis for the answers.},
   3.2={Recount stories, including fables, folktales, and myths from
        diverse cultures; determine the central message, lesson, or moral
        and explain how it is conveyed through key details in the text.},
   3.2={Describe characters in a story (e.g., their traits, motivations,
        or feelings) and explain how their actions contribute to the sequence
        of events.}]

\starttext
\getvariable{RL}{3.3}
\stoptext

如果您想要 key-val-method,您可以使用命令设置变量文本\setvariable

\setvariable{RL}{3.1}{Ask and answer questions to demonstrate understanding
                      of a text, referring explicitly to the text as the basis
                      for the answers.}

另一种方法是buffers存储文本并稍后使用\getbuffer命令访问它们。

\startbuffer [RL.3.1]
Ask and answer questions to demonstrate understanding of
a text, referring explicitly to the text as the basis for
the answers.
\stopbuffer

\startbuffer [RL.3.2]
Recount stories, including fables, folktales, and myths
from diverse cultures; determine the central message,
lesson, or moral and explain how it is conveyed through key
details in the text.
\stopbuffer

\startbuffer [RL.3.2]
Describe characters in a story (e.g., their traits,
motivations, or feelings) and explain how their actions
contribute to the sequence of events.
\stopbuffer

\starttext
\getbuffer[RL.3.1]
\stoptext

答案2

如果我问 ConTeXt\show\def,答案是

\def=\def

这意味着原语\def相对于标准 (Lua)TeX 保持不变。

如下指令

\def\rl.3.1{whatever}

在 TeX 中完全有效,但它只是(重新)定义了控制序列\rl以具有参数文本.3.1和替换文本whatever

具体来说,TeX 要求后面\rl必须跟有四个标记

.3.1

并且任何其他调用\rl都会导致错误

! Use of \rl doesn't match its definition.

请注意,其\rl .3.1行为与 相同\rl.3.1,因为在标记化过程中控制字后面的空格会被忽略。

答案3

在 ConTeXt 中使用该系统怎么样variable?您的示例可以翻译成这样:

\setvariables
  [RL]
  [3.1={Ask and answer questions to demonstrate understanding of a text,
        referring explicitly to the text as the basis for the answers.}]

\starttext

RL.3.1: \getvariable{RL}{3.1}

\stoptext

答案4

您可以尝试另一种方法,使用转变

\documentclass{article}

% https://tex.stackexchange.com/a/64132/123129
\usepackage{pdftexcmds}
\makeatletter
\newcommand*{\CCS}[1]{%
  \stringcases
    {#1}%
    {%
      {RL.3.1}{#1: Ask and answer questions to demonstrate understanding of a text, referring explicitly to the text as the basis for the answers.}%
      {RL.3.2}{#1: Recount stories, including fables, folktales, and myths from diverse cultures; determine the central message, lesson, or moral and explain how it is conveyed through key details in the text.}%
      {RL.3.3}{#1: Describe characters in a story (e.g., their traits, motivations, or feelings) and explain how their actions contribute to the sequence of events}%
    }%
    {[nada]}%
}
\newcommand{\stringcases}[3]{%
  \romannumeral
    \str@case{#1}#2{#1}{#3}\q@stop
}
\newcommand{\str@case}[3]{%
  \ifnum\pdf@strcmp{\unexpanded{#1}}{\unexpanded{#2}}=\z@
    \expandafter\@firstoftwo
  \else
    \expandafter\@secondoftwo
  \fi
    {\str@case@end{#3}}
    {\str@case{#1}}%
}
\newcommand{\str@case@end}{}
\long\def\str@case@end#1#2\q@stop{\z@#1}
\makeatother

\begin{document}

\CCS{RL.3.1}

\CCS{RL.3.2}

\CCS{RL.3.3}

\end{document}

在此处输入图片描述

相关内容