我正在嘗試寫一篇論文,其中有一系列自動編號的內聯引號。
我定義了 a\newcommand
來執行此操作,並且一切正常,直到我嘗試將當前數字保存到變數中,以便我可以引用它,例如在表中。顯然\label
選擇了當前部分,所以這不起作用。如果\label
採用第二個參數以便人們可以編寫\label{mylabel}{mycounter}
那麼那就完美了,但\label
似乎只採用一個參數。
我嘗試修改我的 newcommand ,以便它定義(使用\def
或\newcommand
)一個新標籤(每次調用時作為附加參數傳遞給命令,但我總是遇到語法錯誤)。目前我已經恢復使用定理環境,但這有兩個問題(1)這意味著文字不是內聯的,而是透過換行符與周圍的文字分隔開,其次似乎不可能將定理放入圖標題。我嘗試過使用\savebox
後者,但這似乎也不起作用。
任何幫助感激不盡!謝謝。
答案1
謝謝兩位的回覆。我不知道如何進一步提出第二個建議,但更多的谷歌搜尋同時引導我找到了這個etoolbox
包,我現在有了一個解決方案:
\documentclass{article}
\usepackage{xcolor}
\usepackage{etoolbox}
\newcounter{promptcounter}
\setcounter{promptcounter}{0}
\def\prompt#1#2{\addtocounter{promptcounter}{1}\csdef{#1}{\thepromptcounter}\underline{Prompt-\thepromptcounter: }{\textcolor{teal}{\emph{#2}}}}
\begin{document}
This is a test document. \\prompt\{x\}\{y\} should expand to \textcolor{red}{Prompt-1: y} but also define \\x to be the value of {\textbackslash}thepromptcounter.
\prompt{xxx}{some text}. The value of {\textbackslash}xxx is \xxx. The use of {\textbackslash}etoolbox and {\textbackslash}csdef was critical - it gives an error with plain {\textbackslash}def.
End of test document
\end{document}