in my document I have to type expressions that contain letters with superscripts, enclosed between parentheses, such as
a^{(k,i)}, b^{(k,i)}, \gamma^{(k,i)}
and after a while it became really annoying for me to type those parentheses '(' and ')' each time.
I defined new variables
\newcommand{\ca}[2]{a^{(#1, #2)}}
\newcommand{\cb}[2]{b^{(#1, #2)}}
\newcommand{\cgamma}[2]{\gamma^{(#1, #2)}}
and used \ca k i
or \cgamma k i
. This really made it way easier for me to type equations, however it lacks flexibility. First, I have to define a new variable for each letter. Also, if I want to use subscripts and type \c_3{k,i}
, then it is broken.
My question is, what is the right way to achieve this functionality ?
EDIT : After searching on the internet for a while, I found a solution
\documentclass{article}
\usepackage{amsmath}
\usepackage{etoolbox}
\makeatletter
\newcommand{\removeabs}[1]{%
\ifcat\relax\noexpand#1%
\expandafter\expandafter\expandafter\@gobble\expandafter\string
\fi
#1%
}
\makeatother
\newcommand{\doublesupscr}[1]{\expandafter\newcommand\csname c\removeabs{#1}\endcsname[2]{#1^{(##1, ##2)}}}
\newcommand{\singlesupscr}[1]{\expandafter\newcommand\csname c\removeabs{#1}\endcsname[1]{#1^{(##1)}}}
\forcsvlist{\doublesupscr}{a,b,c}
\forcsvlist{\singlesupscr}{\eta, \gamma}
\begin{document}
\begin{equation*}
\ca k i, \cb k i, \cc k i, \ceta i, \cgamma i
\end{equation*}
\end{document}
which creates the following output
However, I would like to type something like \ca_3 k i
and still get the correct output. Is there a way for newcommand to ignore the subscript as an argument ?
\documentclass{...}
, the required\usepackage
's,\begin{document}
, and\end{document}
. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem.$\ca ki_3$
will work to get a subscript 3.