I am looking for a way to automatically bold certain characters in math mode (for vectors and matrices) but not if the character is followed by an underscore. The substitution of normal characters to their bold counterparts should only happen in math mode.
Ideally, the code
\DeclareVectors{abuvxyz}
\DeclareMatrices{ABM}
\DeclareBB{R}
$A\in R^{q\times n}$ is a matrix with entries $A_{ij}$ and
$v\in R^n$ is a vector with $n$ coordinates, i.e., $v=(v_1,...,v_n)$.
should automatically produce the image The question is how to write the commands
\DeclareVectors{abuvxyz}
\DeclareMatrices{ABM}
\DeclareBB{R}
or if there exists a package that provides the desired behavior.
The closest solution appears to be how to automatic mathbold all capital letters?, although it does not provide a solution to unbold letters that are followed by underscore as in v_1,...,v_n
.
Some Remarks:
- the goal is to improve code readability and reduce as much as possible code overhead. Commands
\bm
,\boldsymbol
etc could of course be used but that is not the goal. - to reduce typing overhead, https://tex.stackexchange.com/a/45724/207532 is interesting but I hope that a solution can get a step further and reduce the need to type backslashes entirely.
- What if you want both a scalar V and a matrix V in the document? That's a tradeoff, if a solution working as above exists, you would have to choose for each letter to be either bold or normal or bb.
unicode-math
, this just works. With legacy font packages, you could loadnewunicodechar
and enable it with\newunicodechar{𝐀}{\ensuremath{\mathbf A}}
, etc.