解析每个字符并将其转换为表列

解析每个字符并将其转换为表列

我正在尝试生成一个数组,该数组将输出给定 LaTex 字体中的大多数 ascii 字符。目前,我有以下可以运行的糟糕代码:

\documentclass{standalone}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[tt=false]{libertine}
\newcommand{\makeasciisymbols}{
    ABCDEFGHIJKLMNOPQRSTUVWXYZ%
    abcdefghijklmnopqrstuvwxyz%
    0123456789()[]\{\}<>=+-*/\%,.;:?!@\&\#\$\_%
}
\newcommand{\makeasciirow}[1]{%
{\fontfamily{#1}\selectfont A}&%
{\fontfamily{#1}\selectfont B}&%
{\fontfamily{#1}\selectfont C}&%
{\fontfamily{#1}\selectfont D}&%
{\fontfamily{#1}\selectfont E}&%
{\fontfamily{#1}\selectfont F}&%
{\fontfamily{#1}\selectfont G}&%
{\fontfamily{#1}\selectfont H}&%
{\fontfamily{#1}\selectfont I}&%
{\fontfamily{#1}\selectfont J}&%
{\fontfamily{#1}\selectfont K}&%
{\fontfamily{#1}\selectfont L}&%
{\fontfamily{#1}\selectfont M}&%
{\fontfamily{#1}\selectfont N}&%
{\fontfamily{#1}\selectfont O}&%
{\fontfamily{#1}\selectfont P}&%
{\fontfamily{#1}\selectfont Q}&%
{\fontfamily{#1}\selectfont R}&%
{\fontfamily{#1}\selectfont S}&%
{\fontfamily{#1}\selectfont T}&%
{\fontfamily{#1}\selectfont U}&%
{\fontfamily{#1}\selectfont V}&%
{\fontfamily{#1}\selectfont W}&%
{\fontfamily{#1}\selectfont X}&%
{\fontfamily{#1}\selectfont Y}&%
{\fontfamily{#1}\selectfont Z}&%
{\fontfamily{#1}\selectfont a}&%
{\fontfamily{#1}\selectfont b}&%
{\fontfamily{#1}\selectfont c}&%
{\fontfamily{#1}\selectfont d}&%
{\fontfamily{#1}\selectfont e}&%
{\fontfamily{#1}\selectfont f}&%
{\fontfamily{#1}\selectfont g}&%
{\fontfamily{#1}\selectfont h}&%
{\fontfamily{#1}\selectfont i}&%
{\fontfamily{#1}\selectfont j}&%
{\fontfamily{#1}\selectfont k}&%
{\fontfamily{#1}\selectfont l}&%
{\fontfamily{#1}\selectfont m}&%
{\fontfamily{#1}\selectfont n}&%
{\fontfamily{#1}\selectfont o}&%
{\fontfamily{#1}\selectfont p}&%
{\fontfamily{#1}\selectfont q}&%
{\fontfamily{#1}\selectfont r}&%
{\fontfamily{#1}\selectfont s}&%
{\fontfamily{#1}\selectfont t}&%
{\fontfamily{#1}\selectfont u}&%
{\fontfamily{#1}\selectfont v}&%
{\fontfamily{#1}\selectfont w}&%
{\fontfamily{#1}\selectfont x}&%
{\fontfamily{#1}\selectfont y}&%
{\fontfamily{#1}\selectfont z}&%
{\fontfamily{#1}\selectfont 0}&%
{\fontfamily{#1}\selectfont 1}&%
{\fontfamily{#1}\selectfont 2}&%
{\fontfamily{#1}\selectfont 3}&%
{\fontfamily{#1}\selectfont 4}&%
{\fontfamily{#1}\selectfont 5}&%
{\fontfamily{#1}\selectfont 6}&%
{\fontfamily{#1}\selectfont 7}&%
{\fontfamily{#1}\selectfont 8}&%
{\fontfamily{#1}\selectfont 9}&%
{\fontfamily{#1}\selectfont (}&%
{\fontfamily{#1}\selectfont )}&%
{\fontfamily{#1}\selectfont [}&%
{\fontfamily{#1}\selectfont ]}&%
{\fontfamily{#1}\selectfont \{}&%
{\fontfamily{#1}\selectfont \}}&%
{\fontfamily{#1}\selectfont <}&%
{\fontfamily{#1}\selectfont >}&%
{\fontfamily{#1}\selectfont =}&%
{\fontfamily{#1}\selectfont +}&%
{\fontfamily{#1}\selectfont -}&%
{\fontfamily{#1}\selectfont *}&%
{\fontfamily{#1}\selectfont /}&%
{\fontfamily{#1}\selectfont \%}&%
{\fontfamily{#1}\selectfont ,}&%
{\fontfamily{#1}\selectfont .}&%
{\fontfamily{#1}\selectfont ;}&%
{\fontfamily{#1}\selectfont :}&%
{\fontfamily{#1}\selectfont ?}&%
{\fontfamily{#1}\selectfont !}&%
{\fontfamily{#1}\selectfont @}&%
{\fontfamily{#1}\selectfont \&}&%
{\fontfamily{#1}\selectfont \#}&%
{\fontfamily{#1}\selectfont \$}&%
{\fontfamily{#1}\selectfont \_}%
}

使用方式如下:

\begin{document}
\tiny
\addtolength{\tabcolsep}{-0.9em}
\begin{tabular}{ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc}
Adventor & \texttt{qag} & \makeasciirow{qag} \\
Bonum & \texttt{qbk} & \makeasciirow{qbk} \\
Chorus & \texttt{qzc} & \makeasciirow{qzc} \\
\end{tabular}
\end{document}

问题 1:如何通过解析命令中的每个字符(解析为一个字符而不是两个字符)并将其变成一列\makeasciirow来自动创建命令?\makeasciisymbols\&

问题2:如何计算里面的字符\makeasciisymbols并将其转换成相应的一行c,以自动创建具有正确列数的表格?

答案1

不确定你加载的东西为什么libertine基本上什么也不做。

将字符序列定义为常量标记列表。然后,您可以用受其影响的字符填充序列,并在项目之间\fontfamily{#1}\selectfont传递该序列。&

\documentclass{standalone}
\usepackage[T1]{fontenc}

\ExplSyntaxOn

\tl_const:Nn \c_vincent_ascii_tl
 {
  ABCDEFGHIJKLMNOPQRSTUVWXYZ
  abcdefghijklmnopqrstuvwxyz
  0123456789
  ()[]\{\}<>=+-*/\%,.;:?!@\&\#\$\_
 }
\seq_new:N \l_vincent_ascii_row_seq

\NewDocumentCommand{\makeasciirow}{m}
 {
  \seq_clear:N \l_vincent_ascii_row_seq
  \tl_map_inline:Nn \c_vincent_ascii_tl
   {
    \seq_put_right:Nn \l_vincent_ascii_row_seq { \fontfamily{#1}\selectfont ##1 }
   }
  \seq_use:Nn \l_vincent_ascii_row_seq { & }
 }

\NewExpandableDocumentCommand{\ncol}{}{\int_eval:n { \tl_count:N \c_vincent_ascii_tl + 2 } }

\ExplSyntaxOff

\begin{document}
\tiny
\setlength{\tabcolsep}{0.5pt}

\begin{tabular}{*{\ncol}{c}}
Adventor & \texttt{qag} & \makeasciirow{qag} \\
Bonum & \texttt{qbk} & \makeasciirow{qbk} \\
Chorus & \texttt{qzc} & \makeasciirow{qzc} \\
\end{tabular}

\end{document}

在此处输入图片描述

相关内容