不帶大括號的指令的捷徑

不帶大括號的指令的捷徑

我想建立一個快捷方式

\textsubscriptARGS

ARGS任何數字。

我想輸入類似的內容123\a33332並具有相同的輸出123\textsubscript{33332}

我嘗試過\def\newcommand沒有成功謝謝!

我嘗試了 \def\aa #1#2#3{\textsubscript{#1#2#3}} 並且它有效,但只有當有 3 個參數時,你知道如何將參數設為可選或包含所有空格之前的字元作為一個參數?

答案1

上面寫著各種各樣的錯誤:

在此輸入影像描述

\documentclass{article}

\usepackage{xspace}
\def\aa#1 {\textsubscript{#1}\xspace}

\begin{document}

Here is some 123\aa4 text together with
        some 123\aa45 text together with
        some 123\aa456 text together with
        some 123\aa4567 text together with
        some 123\aa45678 text together with
        some 123\aa456789 text together with
        some 123\textsubscript{4567890}.

\end{document}

為什麼?

  • \aa已經定義(如瑞典字母 å)。

  • \aafor在句尾的用法不一致,因為\def的參數文本需要一個空格作為其參數的結束分隔符號。以 a 為條件.沒問題,但是,, or !, or ?, or ...會發生什麼事?

  • 的缺點xspace

答案2

如果你只想要整數,你可能執行如下操作:

\documentclass{article}
\usepackage{xspace}

\newcommand{\wrongwaytodosubscripts}{%
  \afterassignment\wwtdss\count255=
}
\def\wwtdss{\textsubscript{\the\count255}\xspace}

\begin{document}

123\wrongwaytodosubscripts123 followed by whatever.

123\wrongwaytodosubscripts123.

\end{document}

從我選擇的巨集名稱中應該可以清楚地看出我是否建議這樣做。

在此輸入影像描述

不要這樣做!它很容易出錯並且有一些限制。

相關內容