Designated Constants in LaTeX

I have several lemmas in which I specify the constants $ C_1 $, $ C_2 $, etc. for subsequent reference. Naturally, this is annoying when I later insert a new constant definition in the middle. I would like it to be a macro that allows me to label constants and handle the numbering for me. I think something like strings

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

Is it possible?

+5
source share
3 answers

Extension of the rcollyer counter usage offer:

%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 has been edited so that labels are longer than one character)

And here is a piece of code 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.
+3
source

What you are looking for is to create your own counter .

0
source

, , ,

\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 ....

, ( , )

0

All Articles