开发者

Labeled constants in LaTeX

开发者 https://www.devze.com 2023-01-05 16:11 出处:网络
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

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 开发者_StackOverflowlets 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?


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.


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


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)

0

精彩评论

暂无评论...
验证码 换一张
取 消