14

I want to use a custom symbol in my document that is treated like any other letter or math symbol by LaTeX. I do not want to superimpose existing symbols in order to create a new one but rather create one from scratch.

Is there a way to just create the symbol using, say, Inkscape and tell LaTeX to print that when I call a specific macro? There is of course the possibility of using \includegraphics[height=1em], but I imagine that that is not a very effective approach. Can I let LaTeX use my symbol like any other math symbol?

Do I have to create an entire font (consisting of only one character) or is it possible to this in a simpler manner?

5
  • 2
    The \includegraphics approach can be made efficient by invoking it once to set the symbol in a saved box, and then the box can be efficiently recalled at need. May 5, 2014 at 15:30
  • 1
    @StevenB.Segletes for pdflatex at least it does that anyway if you load the same image twice May 5, 2014 at 15:31
  • @DavidCarlisle I did not know that. In that case, there is nothing not "effective" about that approach, other than a \raisebox may be required if the new symbol is a descender. May 5, 2014 at 15:33
  • @schtreber You could also export some svg from Inkscape using code.google.com/p/inkscape2tikz and then define a macro which you can use like here: tex.stackexchange.com/a/116324
    – LaRiFaRi
    May 6, 2014 at 17:01
  • You could have a look at the technique I used here : tex.stackexchange.com/a/188705/34551
    – Clément
    Jan 13, 2015 at 13:47

1 Answer 1

14

This solution demonstrates how an \includegraphics approach could be made to work conveniently.

If the new symbol should conform to the vertical extent of an existing glyph, then this approach will work handily. In the MWE, I make the symbol \schtreber conform to the height of a "b" and then a "g", respectively. It will scale with math style.

If the symbol is a relation or operator, the definition could include a \mathrel or \mathop.

\documentclass{article}
\usepackage{scalerel}
\begin{document}
\def\schtreber{\scalerel*{\includegraphics{schtreber}}{b}}

$ab\schtreber c \scriptscriptstyle ab\schtreber c$

$ y = x^{\schtreber}$

\def\schtreber{\scalerel*{\includegraphics{schtreber}}{g}}

$ab\schtreber c \scriptscriptstyle ab\schtreber c$

$ y = x^{\schtreber}$

\end{document}

enter image description here

If the vertical extent is to be arbitrary, a \rule may be used for the target size, where \LMpt (local-mathstyle pts) or \LMex (local-mathstyle ex's) are used to define the dimensions of the rule. Here I place the image in a \savebox initially, in the event that some flavors of TeX don't save a local copy from \includegraphics.

\documentclass{article}
\usepackage{scalerel}
\newsavebox\schtreberbox
\savebox\schtreberbox{\includegraphics{schtreber}}
\def\schtreber{\scalerel{\usebox{\schtreberbox}}{\rule[-2\LMpt]{0pt}{8\LMpt}}}
\begin{document}
$ab\schtreber c \scriptscriptstyle ab\schtreber c$\par
$ y = x^{\schtreber}$
\end{document}

enter image description here

The advantage of the former, rather than the latter approach is that the method will also work in both text and math mode, as expected:

\documentclass{article}
\usepackage{scalerel}
\newsavebox\schtreberbox
\savebox\schtreberbox{\includegraphics{schtreber}}
\def\schtreber{\scalerel*{\usebox{\schtreberbox}}{b}}
\begin{document}
$ab\schtreber c \scriptscriptstyle ab\schtreber c$\par
$ y = x^{\schtreber}$

In text\schtreber, \LARGE text\schtreber.
\end{document}

enter image description here

5
  • It would have been nicer if schtreber was an eps or svg file…
    – Clément
    Jan 13, 2015 at 13:48
  • 1
    @Clément This example was for illustrative purposes. The graphics format is irrelevant to scalerel but obviously must be compatible with \includegraphics. Jan 13, 2015 at 13:53
  • 1
    @Clément I would add that even \includegraphics is not a requirement for this approach. Any graphic that can be placed into a LaTeX box would work. Jan 13, 2015 at 14:00
  • There is no space after the symbol, how do I fix it?
    – Ziofil
    Mar 25, 2021 at 3:02
  • @Ziofil You can either edit the image to add a little horizontal space (called sidebearing), or you can add space to the definition: \def\schtreber{\kern1pt\scalerel*{\usebox{\schtreberbox}}{b}\kern1pt} Mar 25, 2021 at 9:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.