The primary struggle here seems to be that you want a symbol that works with all math styles without having to adjust the spacing and size every time you use it. The solution here is to define the symbol use either \mathchoice
or \mathpalette
. For details on that, see
Let's assume you have some super intricate symbol
You may have started with a hand-drawing and traced it. Regardless, the above is a vectorized version of the symbol in the form of an image. I'll just call it a symbol.
Define your symbol via \mathchoice
in the following way:
\newcommand{\mysymbol}{%
\mathchoice
{\includegraphics[height=1em]{super_intricate_symbol}}
{\includegraphics[height=1ex]{super_intricate_symbol}}
{\includegraphics[height=.7ex]{super_intricate_symbol}}
{\includegraphics[height=.5ex]{super_intricate_symbol}}
}
This allows you to tailor the symbol's display size (and related spacing/alignment) based on the math style, even though you're only using a single image. Here's an example of a use-case:
\documentclass{article}
\usepackage{graphicx}
\newcommand{\mysymbol}{%
\mathchoice
{\includegraphics[height=1em]{super_intricate_symbol}} % \displaystyle
{\includegraphics[height=1ex]{super_intricate_symbol}} % \textstyle
{\includegraphics[height=.7ex]{super_intricate_symbol}}% \scriptstyle
{\includegraphics[height=.5ex]{super_intricate_symbol}}% \scriptscriptstyle
}
\begin{document}
\[
x\ {\textstyle x}^{x^x} \quad
x\mysymbol\ {\textstyle x\mysymbol}^{x\mysymbol^{x\mysymbol}} \quad
x\mysymbol\ {\textstyle x\mysymbol}_{x\mysymbol_{x\mysymbol}} \quad
x\ {\textstyle x}_{x_x}
\]
\end{document}
What you lose using this approach is the font weight that typically is adjusted for smaller versions. Notice how the stem of the x
remains fairly thick even though its written in \scriptscriptstyle
. Here's a direct comparison using x
as your symbol:
\newcommand{\mysymbol}{%
\mathchoice
{\resizebox{!}{1ex}{$\textstyle x$}} % \displaystyle
{\resizebox{!}{1ex}{$\textstyle x$}} % \textstyle
{\resizebox{!}{.7ex}{$\textstyle x$}}% \scriptstyle
{\resizebox{!}{.5ex}{$\textstyle x$}}% \scriptscriptstyle
}
The different font weights are noticeable within \scriptscriptstyle
(the superscript of the superscript). To that end, you could define different weight versions of your symbol and use them in the respective components (\...style
) in \mathchoice
. However, depending on the use-case and/or symbol construction, this might not be an issue.
You would follow a similar approach to the above even if you defined your symbol using an overlay of multiple symbols; that is, define appropriate spacing/layout that might depend on the math style you're in.
The fonts should be stored in your TeX Directory Structure (TDS) under a folder called fonts
. If you want to know which fonts are used, then you can add \showoutput
to a small document and use a symbol and look at the .log
. For example, the following minimal example
\documentclass{article}
\begin{document}
\showoutput
$\alpha$
\end{document}
reveals (I've added highlights for the elements on the page; \alpha
and the page number):
Completed box being shipped out [1]
\vbox(633.0+0.0)x407.0
.\glue 16.0
.\vbox(617.0+0.0)x345.0, shifted 62.0
..\vbox(12.0+0.0)x345.0, glue set 12.0fil
...\glue 0.0 plus 1.0fil
...\hbox(0.0+0.0)x345.0
..\glue 25.0
..\glue(\lineskip) 0.0
..\vbox(550.0+0.0)x345.0, glue set 539.94232fil
...\write-{}
...\glue(\topskip) 5.69446
...\hbox(4.30554+0.0)x345.0, glue set 323.56596fil
....\hbox(0.0+0.0)x15.0
....\mathon
....\OML/cmm/m/it/10 % <------------------------------- \alpha
....\kern0.03702
....\mathoff
....\penalty 10000
....\glue(\parfillskip) 0.0 plus 1.0fil
....\glue(\rightskip) 0.0
...\glue 0.0 plus 1.0fil
...\glue 0.0
...\glue 0.0 plus 0.0001fil
..\glue(\baselineskip) 23.55556
..\hbox(6.44444+0.0)x345.0, glue set 170.0fil
...\glue 0.0 plus 1.0fil
...\OT1/cmr/m/n/10 1 % <--------------------------------- page number (1)
...\glue 0.0 plus 1.0fil
You'll see that \alpha
uses cmm
- Computer Modern Math with a it
alics shape in 10
point. You can then print the entire font table for cmmi10
via \fonttable
:
\documentclass{article}
\usepackage{fonttable}
\begin{document}
\fonttable{cmmi10}
\end{document}
\show\alpha
also identifies the position as \mathchar"10B
.
You also lose possible kerning corrections which are specific to the font. However, all of these losses might be nothing compared to the convenience from managing content the way you want.
Related: Is there a simple way to print out all the available characters in a LaTeX font set?
\includegraphics
approach to condition on the math style, thereby automating the sizing choice. For that, there's\mathchoice
and\mathpalette
.