I need to go and rework a bunch of notation in a large body of work. But I might change my mind later, so I want to move to defining the notation a bit more semantically. E.g. writing \v x
to represent a vector, so I can later decide to format vectors in different ways.
On thing that is currently wrong with it is that I write A_i
to represent that $ i^{\text {th}}$ column vector. After looking at other similar works, I have concluded that A_{:,i}
would be clearer. So I have defined a macro to smartly determine if a :
should be added.
I called it \i
to be concise since I will be writing it often.
Code + Example
\documentclass{article} \usepackage{xparse,xstring,etoolbox} \renewcommand{\v}[1]{\tilde{#1}} % a vector \newcommand{\ind}[2]{#1_{#2}} % indexed %% Smart indexing and naming code \newcommand{\ifupper}[3]{ \normalexpandarg \exploregroups \StrCount{ABCDEFGHIJKLMNOPQRSTUVWXYZ}{#1}[\uppercount] \ifnumgreater{\uppercount}{0}{#2}{#3} } %smart index \DeclareDocumentCommand{\i}{u{_} m}{ \ifupper{#1}% {% just a single uppercase character, i.e. a matrix %make sure the index is the right length \StrCount{#2}{,}[\indcount] \ifnumgreater{\indcount}{0} { % Got multiple indexes so all good \ind{#1}{#2} } { % Only 1 index so grab the column \ind{#1}{{:,#2}} } }% {% Not just a single upper case character \ind{#1}{#2} } } %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Example document \begin{document} \begin{tabular}{r l} $ \i {\v x}_i$ & the $ i$ th element of the vector $ \v x$ \ $ \i{X}_{i,j}$ & the row $ i$ and column $ j$ element of the matrix $ X$ \ $ \i{X}_i$ & the $ i$ th column vector of the matrix $ X$ \ $ \i{X}_{i,:}$ & the $ i$ th row vector of the matrix $ X$ \ \end{tabular} \end{document}
Example document output
Crossref: https://tex.stackexchange.com/q/406963/5834