我正在嘗試生成一個數組,該數組將輸出給定 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}
問題一:如何透過解析命令的每個字元(解析為一個字元而不是兩個字元)並將其轉換為一列\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}