具有 \chardef 特殊行为的原语

具有 \chardef 特殊行为的原语

\chardef语表现出一种特殊的行为:命令

\chardef\controlSequence=<number>

表现得好像它之前是

\let\controlSequence=\relax

(参见这个问题)。

是否有任何其他类似的 TeX 原语,\p其行为就像某些标记在\p扩展/执行之前被(重新)定义一样?

* 我正在寻找一份详尽的清单,但也欢迎部分清单。

答案1

\mathchardef数学字符的行为方式类似。

\tracingall
\chardef\foo=123
\mathchardef\baz=123
\csname @@end\endcsname\end

包含.log

{changing \foo=undefined}
{into \foo=\relax}

{changing \baz=undefined}
{into \baz=\relax}

其他命令:

\countdef
\dimendef
\skipdef
\muskipdef
\toksdef

该列表来自源代码tex.web(关键字shorthand_def):

@ A \.{\\chardef} creates a control sequence whose |cmd| is |char_given|;
a \.{\\mathchardef} creates a control sequence whose |cmd| is |math_given|;
and the corresponding |chr| is the character code or math code. A \.{\\countdef}
or \.{\\dimendef} or \.{\\skipdef} or \.{\\muskipdef} creates a control
sequence whose |cmd| is |assign_int| or \dots\ or |assign_mu_glue|, and the
corresponding |chr| is the |eqtb| location of the internal register in question.

@d char_def_code=0 {|shorthand_def| for \.{\\chardef}}
@d math_char_def_code=1 {|shorthand_def| for \.{\\mathchardef}}
@d count_def_code=2 {|shorthand_def| for \.{\\countdef}}
@d dimen_def_code=3 {|shorthand_def| for \.{\\dimendef}}
@d skip_def_code=4 {|shorthand_def| for \.{\\skipdef}}
@d mu_skip_def_code=5 {|shorthand_def| for \.{\\muskipdef}}
@d toks_def_code=6 {|shorthand_def| for \.{\\toksdef}}

@<Put each...@>=
primitive("chardef",shorthand_def,char_def_code);@/
@!@:char_def_}{\.{\\chardef} primitive@>
primitive("mathchardef",shorthand_def,math_char_def_code);@/
@!@:math_char_def_}{\.{\\mathchardef} primitive@>
primitive("countdef",shorthand_def,count_def_code);@/
@!@:count_def_}{\.{\\countdef} primitive@>
primitive("dimendef",shorthand_def,dimen_def_code);@/
@!@:dimen_def_}{\.{\\dimendef} primitive@>
primitive("skipdef",shorthand_def,skip_def_code);@/
@!@:skip_def_}{\.{\\skipdef} primitive@>
primitive("muskipdef",shorthand_def,mu_skip_def_code);@/
@!@:mu_skip_def_}{\.{\\muskipdef} primitive@>
primitive("toksdef",shorthand_def,toks_def_code);@/
@!@:toks_def_}{\.{\\toksdef} primitive@>

@ @<Cases of |print_cmd_chr|...@>=
shorthand_def: case chr_code of
  char_def_code: print_esc("chardef");
  math_char_def_code: print_esc("mathchardef");
  count_def_code: print_esc("countdef");
  dimen_def_code: print_esc("dimendef");
  skip_def_code: print_esc("skipdef");
  mu_skip_def_code: print_esc("muskipdef");
  othercases print_esc("toksdef")
  endcases;
char_given: begin print_esc("char"); print_hex(chr_code);
  end;
math_given: begin print_esc("mathchar"); print_hex(chr_code);
  end;

@ We temporarily define |p| to be |relax|, so that an occurrence of |p|
while scanning the definition will simply stop the scanning instead of
producing an ``undefined control sequence'' error or expanding the
previous meaning.  This allows, for instance, `\.{\\chardef\\foo=123\\foo}'.

@<Assignments@>=
shorthand_def: begin n:=cur_chr; get_r_token; p:=cur_cs; define(p,relax,256);
  scan_optional_equals;
  case n of
  char_def_code: begin scan_char_num; define(p,char_given,cur_val);
    end;
  math_char_def_code: begin scan_fifteen_bit_int; define(p,math_given,cur_val);
    end;
  othercases begin scan_eight_bit_int;
    case n of
    count_def_code: define(p,assign_int,count_base+cur_val);
    dimen_def_code: define(p,assign_dimen,scaled_base+cur_val);
    skip_def_code: define(p,assign_glue,skip_base+cur_val);
    mu_skip_def_code: define(p,assign_mu_glue,mu_skip_base+cur_val);
    toks_def_code: define(p,assign_toks,toks_base+cur_val);
    end; {there are no other cases}
    end
  endcases;
  end;

还有另一种不同的情况,其中控制序列被分配给\relax:如果由构造的命令序列\csname ...\endcsname未定义,则将其分配给\relax

案例\font,请参阅 Joseph Wright 的评论

\tracingall
\font\foo\foo
\csname @@end\endcsname\end

.log\foo暂时定义成不可扩展的命令:

{changing \foo=undefined}
{into \foo=select font nullfont}

答案2

完整列表可以从tex.web我在https://tex.stackexchange.com/a/376435/4427

在此处输入图片描述

还有一种情况\font稍有不同,即分配的是控制序列\nullfont而不是\relax

相关内容