2

I wish to use custom symbols in my math boxes. They are very simple symbols, but I use them very often in my LaTeX document (so far, I've used them at least 150 times). I have managed to put them in the document by defining a new command using \includegraphics to import a 2KB PDF of them I saved using Tikz, but when I call this command 150 times, the file is way too slow to compile.

The symbols are simple, though I need the freedom to place more math around them, as follows (by the way, I wonder if there is a way to not make b droop like that):

enter image description here

Each letter there is a parameter.

As can be seen, the symbols themselves are very simple, three lines at most. I cannot believe that there isn't a faster way to compile them. I have written them into Tikz as follows (this example is of an X which isn't in the image above):

\documentclass[tikz]{standalone}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}%
    \draw (-1ex,-2ex) -- (1ex,2ex);%
    \draw (-1ex,2ex) -- (1ex,-2ex);%
\end{tikzpicture}%
\end{document}

I saved this as a PDF, which ended up having 2KB in size, and imported it into my main .tex file using (this example is of the K):

\newcommand{\knot}[6][1]{%
\prescript{#4}{#2}{\vcenter{\hbox{
\includegraphics[page=1, scale = #1]{K-notation/knot.pdf}
\newcommand{\starcup}{$\sqcup$\kern-0.58em{$\star$}}
}}^{#5}_{#3}} #6
}

% Then, inside math text (after \begin{document}, of course):
\knot{\Omega}{\boldsymbol{\eta\cdot}}{a}{b}{c}

I have found many ways to import such a custom character into LaTeX with this forum, but none of them proved to be any faster. Even though this is already much faster than drawing the symbols using Tikz every time, it still takes too long for such a simple symbol.

3
  • 2
    you could store the tikz picture or the part with the graphics in a box (see \newsavebox and \sbox) and then reuse the box as often your want. Feb 20, 2023 at 18:42
  • That works very well! It compiles a lot faster now, but I now I don't know how to adjust the symbol size... (sometimes, such as in footnotes or exponents, it's better if it is smaller) Is there a way to do this? Feb 20, 2023 at 19:19
  • 2
    well how many sizes do you need? 3 or 4? so make four boxes. Feb 20, 2023 at 19:44

1 Answer 1

3

Here are macros that (I think) do what you want. Each symbol is a tikzpicture that is stored in an \sbox so it won't be redrawn each time it's called. Then it's turned into an operator so the \sideset command (amsmath) will work to place the sub- and superscripts. The scalerel package is used to scale and position the symbols just like \sum.

Two global parameters can be adjusted to your liking. First, \symscale will affect line thickness in the symbols: larger numbers produce thinner lines. Second, \trimlen controls the horizontal spacing between the symbols and their scripts.

enter image description here

\documentclass{article}

\usepackage{tikz, scalerel, amsmath}

\newcommand{\symscale}{.25}
\newcommand{\trimlen}{1pt}

\newsavebox{\Kforward}
\sbox{\Kforward}{\tikz[scale=\symscale, trim left=-\trimlen, trim right=\symscale cm+\trimlen]
    {\draw(0,0)--(0,2)(1,2)--(0,1)--(1,0);}}
\DeclareMathOperator{\KSYM}{\scalerel*{\usebox{\Kforward}}{\sum}}
\newcommand{\Ksym}[4]{\sideset{^{#3}_{#1}}{^{#4}_{#2}}\KSYM}

\newsavebox{\Kbackward}
\sbox{\Kbackward}{\tikz[scale=\symscale, trim left=-\trimlen, trim right=\symscale cm+\trimlen]
    {\draw(1,0)--(1,2)(0,2)--(1,1)--(0,0);}}
\DeclareMathOperator{\KBSYM}{\scalerel*{\usebox{\Kbackward}}{\sum}}
\newcommand{\Kbsym}[4]{\sideset{^{#3}_{#1}}{^{#4}_{#2}}\KBSYM}

\newsavebox{\Lforward}
\sbox{\Lforward}{\tikz[scale=\symscale, trim left=-\trimlen, trim right=\symscale cm+\trimlen]
    {\draw(0,2)--(1,0)(0,0)--(.5,1);}}
\DeclareMathOperator{\LSYM}{\scalerel*{\usebox{\Lforward}}{\sum}}
\newcommand{\Lsym}[3]{\sideset{^{#3}_{#1}}{_{#2}}\LSYM}

\newsavebox{\Lbackward}
\sbox{\Lbackward}{\tikz[scale=\symscale, trim left=-\trimlen, trim right=\symscale cm+\trimlen]
    {\draw(1,2)--(0,0)(1,0)--(.5,1);}}
\DeclareMathOperator{\LBSYM}{\scalerel*{\usebox{\Lbackward}}{\sum}}
\newcommand{\Lbsym}[3]{\sideset{_{#1}}{^{#3}_{#2}}\LBSYM}

\newsavebox{\Xsymbol}
\sbox{\Xsymbol}{\tikz[scale=\symscale, trim left=-\trimlen, trim right=\symscale cm+\trimlen]
    {\draw(0,0)--(1,2)(0,2)--(1,0);}}
\DeclareMathOperator{\XSYM}{\scalerel*{\usebox{\Xsymbol}}{\sum}}
\newcommand{\Xsym}[4]{\sideset{^{#3}_{#1}}{^{#4}_{#2}}\XSYM}

\begin{document}

\[
\Ksym{\Omega}{\boldsymbol{\eta\cdot}}{\,a}{b}c\qquad
d\Kbsym{\Omega}{\boldsymbol{\eta\cdot}}{\,a}{b}\qquad
d\Lsym{\Omega}{\boldsymbol{\eta\cdot}}{\,a}c\qquad
d\Lbsym{\Omega}{\boldsymbol{\eta\cdot}}{b}c\qquad
d\Xsym{\Omega}{\boldsymbol{\eta\cdot}}{\,a}{b}c
\]

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .