LaTeX 中的标记常量

发布于 2024-09-07 17:44:25 字数 289 浏览 1 评论 0原文

我有几个引理,在其中指定常量 $C_1$、$C_2$ 等,以供以后参考。当然,当我后来在中间插入一个新的常量定义时,这很烦人。我想要的是一个宏,它可以让我为常量分配标签并为我处理编号。我在想

%% Pseudocode
\begin{lemma}
    \newconstant{important-bound}
    We will show that $f(x) \le \ref{important-bound} g(x)$ for all $x$.
\end{lemma}

这可能吗?

I have several lemmas in which I specify constants $C_1$, $C_2$, and so forth for later reference. Naturally, this is annoying when I later insert a new constant definition in the middle. What I'd like is a macro that lets me assign labels to constants and handles the numbering for me. I'm thinking something along the lines of

%% Pseudocode
\begin{lemma}
    \newconstant{important-bound}
    We will show that $f(x) \le \ref{important-bound} g(x)$ for all $x$.
\end{lemma}

Is this possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

墨落成白 2024-09-14 17:44:25

扩展 rcollyer 使用计数器的建议:(

%counter of current constant number:    
  \newcounter{constant} 
%defines a new constant, but does not typeset anything:
  \newcommand{\newconstant}[1]{\refstepcounter{constant}\label{#1}} 
%typesets named constant:
  \newcommand{\useconstant}[1]{C_{\ref{#1}}}

编辑此代码以允许标签长度超过一个字符)

下面是一个似乎有效的代码片段:

I want to define two constants:\newconstant{A}\newconstant{B}$\useconstant{A}$ and
$\useconstant{B}$. Then I want to use $\useconstant{A}$ again.

Expanding on rcollyer's suggestions of using a counter:

%counter of current constant number:    
  \newcounter{constant} 
%defines a new constant, but does not typeset anything:
  \newcommand{\newconstant}[1]{\refstepcounter{constant}\label{#1}} 
%typesets named constant:
  \newcommand{\useconstant}[1]{C_{\ref{#1}}}

(This code was edited to allow labels longer than one character)

And here is a code snippet that seems to work:

I want to define two constants:\newconstant{A}\newconstant{B}$\useconstant{A}$ and
$\useconstant{B}$. Then I want to use $\useconstant{A}$ again.
自演自醉 2024-09-14 17:44:25

您需要创建自己的计数器

What you're looking for is to create your own counter.

木緿 2024-09-14 17:44:25

扩展 Aniko 的答案,我用了
这个分层宏,以便它创建一个简写标签,

\newcounter{constant}
\newcommand{\newconstant}[1]{\refstepcounter{constant}\label{#1}}
\newcommand{\useconstant}[1]{C_{\ref{#1}}}
\newcommand{\defconstant}[1]{ \newconstant{c_#1}\expandafter\newcommand\csname c#1\endcsname{\useconstant{c_#1}} }  %

因此要使用它,您需要小心

\defconstant{a}
\defconstant{b}
There exist constant $\ca$ and $\cb$ such that ....

不要覆盖现有命令(我确信它无论如何都会警告您)

Expanding on Aniko's answer, I used
this layered macro so that it created a shorthand for the label,

\newcounter{constant}
\newcommand{\newconstant}[1]{\refstepcounter{constant}\label{#1}}
\newcommand{\useconstant}[1]{C_{\ref{#1}}}
\newcommand{\defconstant}[1]{ \newconstant{c_#1}\expandafter\newcommand\csname c#1\endcsname{\useconstant{c_#1}} }  %

So to use this, you would then do

\defconstant{a}
\defconstant{b}
There exist constant $\ca$ and $\cb$ such that ....

careful not to overwrite existing commands (i'm sure it would warn you anyhow)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文