我正在用 LaTeX 写一篇稍微有点数学的论文,遇到了以下问题。我找到了一个替代的(也是很好的)解决方案,但我很好奇是否有人知道如何做到这一点(文章末尾的 MWE)。
我希望能够将上标和下标添加到我为论文创建的自定义命令中。请考虑以下命令:
\NewDocumentCommand \conceptsymbol {} {L}
\NewDocumentCommand \conceptvalue { m O{\conceptsymbol} } { #2(#1) }
我之所以这样做,是因为这篇论文还处于早期阶段,我们可能会改变符号。现在考虑以下四种可能性($
为简洁起见省略)
\conceptsymbol, \conceptsymbol', \conceptsymbol_1 and \conceptsymbol_1'.
这些将被渲染为L
、L'
和。我对此没有问题,L_1
但是L_1'
,我想使用 来引用每个概念的一些属性conceptvalue
。我可以轻松更改作为可选参数使用的符号conceptvalue
。我可以使用默认参数
\conceptvalue{i} % L(i)
或者我可以设置不同的值
\conceptvalue{i}[\conceptsymbol'] % L'(i)
\conceptvalue{i}[\conceptsymbol_1] % L_1(i)
\conceptvalue{i}[\conceptsymbol_1'] % L_1'(i)
我想做同样的事情,但要更简短一些。例如,我可以写
\conceptvalue{i}' % L(i)'
\conceptvalue{i}_1 % L(i)_1
\conceptvalue{i}_1' % L(i)_1'
但这无法正确呈现符号。有人知道如何缩短它吗?谢谢大家!
完整 MWE:
\documentclass[12pt]{article}
\pdfoutput=1
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{xparse}
\usepackage{booktabs}
\usepackage{multicol}
\NewDocumentCommand \conceptsymbol {} {L}
\NewDocumentCommand \conceptvalue { m O{\conceptsymbol} }
{ #2(#1) }
\begin{document}
\allowdisplaybreaks
\title{The hardest part of any paper is dealing with \LaTeX}
\author{Me, myself, and some nice {\tt tex.stackexchange} users}
\maketitle
\section{Please, help}
My commands are:
\begin{verbatim}
\NewDocumentCommand \conceptsymbol {} {L}
\NewDocumentCommand \conceptvalue { m O{\conceptsymbol} }
{ #2(#1) }
\end{verbatim}
Assume that $\conceptsymbol$ refers to a sequence of $n$ elements and that $\conceptvalue{i}$ denotes the $i$th element in the sequence. Suppose now that I have several sequences $\conceptsymbol$, $\conceptsymbol'$, $\conceptsymbol_1$ and $\conceptsymbol_1'$.
{\small
\begin{table}[h]
\centering
\begin{tabular}{cl}
\toprule
\multicolumn{2}{c}{What I have} \\
\midrule
$\conceptvalue{i}$ & \verb|\conceptvalue{i}| \\
$\conceptvalue{i}'$ & \verb|\conceptvalue{i}'| \\
$\conceptvalue{i}_1$ & \verb|\conceptvalue{i}_1| \\
$\conceptvalue{i}_1'$ & \verb|\conceptvalue{i}_1'| \\
\midrule
$\conceptvalue{i}$ & \verb|\conceptvalue{i}| \\
$\conceptvalue{i}[\conceptsymbol']$ & \verb|\conceptvalue{i}[\conceptsymbol']| \\
$\conceptvalue{i}[\conceptsymbol_1]$ & \verb|\conceptvalue{i}[\conceptsymbol_1]| \\
$\conceptvalue{i}[\conceptsymbol_1']$ & \verb|\conceptvalue{i}[\conceptsymbol_1']| \\
\bottomrule
\end{tabular}
\quad
\begin{tabular}{cl}
\toprule
\multicolumn{2}{c}{Shorter way?} \\
\midrule
$\conceptsymbol(i)$ & ? \\
$\conceptsymbol'(i)$ & ? \\
$\conceptsymbol_1(i)$ & ? \\
$\conceptsymbol_1'(i)$ & ? \\
\bottomrule
\end{tabular}
\end{table}
}
\end{document}