# Creating a custom character that automatically adjusts size in math mode? [duplicate]

After a lot of searching, I finally found the .pdf's for the elusive Griffiths script r character used in his ubiquitous undergraduate electrodynamics book. I made a simple package that allows me to use the figures as math characters:

\NeedsTeXFormat{LaTeX2e}[1999/12/01]
\ProvidesPackage{scriptr}[2014/06/18 Griffiths' Script r Character]
\RequirePackage{graphicx}

\def\rcurs{{\mbox{$\resizebox{.101in}{.08in}{\includegraphics{C:/Program Files/MiKTeX 2.9/tex/latex/scriptr/ScriptR.pdf}}$}}}
\def\brcurs{{\mbox{$\resizebox{.104in}{.08in}{\includegraphics{C:/Program Files/MiKTeX 2.9/tex/latex/scriptr/BoldR.pdf}}$}}}
\def\hrcurs{{\mbox{$\hat \brcurs$}}}


There are two issues with it that I'd like to fix.

1. I would like to make it so that the character automatically adjusts its size in the main body of a document depending on the size of the font. For example, in 12pt font it looks like this: In this case it looks as though it fits in perfectly with the rest of the text. However, in a smaller font size such as 10pt, it looks a little too big compared to its adjacent characters. In fact, it almost looks like capital letter:

2. A similar problem persists whenever working with the character in math mode. When used with \frac, the character looks fine: But when used with \tfrac, the character looks far too big compared to what's in the numerator:

What's the best way for me to make it behave more like an actual character in math mode?

-

## marked as duplicate by Andrew Swann, Jesse, Thorsten, zeroth, GuidoJun 20 at 9:13

this question might be helpful: Problems with custom symbols –  barbara beeton Jun 19 at 18:02

Directly adapting my answer at How to use a custom, scalable, symbol in LaTeX, I screen saved your two glyphs into jpeg files and cropped them.

Then, I use scalerel to make them scale to the size of something that is scalable in math mode. It will also work nicely in text mode, if the fontsize is changed (in this MWE, to \tiny is demonstrated).

\documentclass{article}
\usepackage{scalerel}
\begin{document}
\centering
Scale it to the size of r''
\def\scriptr{\scalerel*{\includegraphics{scriptr}}{r}}
\def\scriptrb{\scalerel*{\includegraphics{scriptrb}}{r}}

$ab\scriptr c \scriptscriptstyle ab\scriptr c$

$y = x^{\scriptr}$

$ab\scriptrb c \scriptscriptstyle ab\scriptrb c$

$y = x^{\scriptrb}$

tiny: {\tiny ab\scriptr\scriptrb c}

Scale it to a scalable rule

\newsavebox\scriptrbox
\savebox\scriptrbox{\includegraphics{scriptr}}
\def\scriptr{\scalerel{\usebox{\scriptrbox}}{\rule[-.2\LMex]{0pt}{1.4\LMex}}}
\newsavebox\scriptrbbox
\savebox\scriptrbbox{\includegraphics{scriptrb}}
\def\scriptrb{\scalerel{\usebox{\scriptrbbox}}{\rule[-.2\LMex]{0pt}{1.4\LMex}}}

$ab\scriptr c \scriptscriptstyle ab\scriptr c$\par
$y = x^{\scriptr}$

$ab\scriptrb c \scriptscriptstyle ab\scriptrb c$\par
$y = x^{\scriptrb}$

tiny: {\tiny ab\scriptr\scriptrb c}

\end{document}


-
This worked perfectly. Thank you so much! –  Vaeryn Jun 19 at 19:09

The result is poor because I could only do a screen capture; adjust the height to what's necessary for adapting the symbol to the font.

\documentclass{article}
\usepackage{amsmath,graphicx}

\newcommand\rcurs{\text{\includegraphics[height=2ex]{Rmed}}}
\newcommand\brcurs{\text{\includegraphics[height=2ex]{Rbold}}}

\begin{document}

Since $\hat{\brcurs}=\brcurs/\rcurs$, we know that
$\hat{\brcurs}/\rcurs^{2}=\brcurs/\rcurs^{3}$.
Furthermore $1/\rcurs^{3}$ can be rewritten as
$\tfrac{1}{\rcurs^{3}}= \frac{1}{\rcurs^{3}}= \bigl[(x-x')^{2}+(y-y')^{2}+(z-z')^{2}\bigr]^{3/2}.$

\huge
Since $\hat{\brcurs}=\brcurs/\rcurs$, we know that
$\hat{\brcurs}/\rcurs^{2}=\brcurs/\rcurs^{3}$.
Furthermore $1/\rcurs^{3}$ can be rewritten as
$\tfrac{1}{\rcurs^{3}}= \frac{1}{\rcurs^{3}}= \bigl[(x-x')^{2}+(y-y')^{2}+(z-z')^{2}\bigr]^{3/2}.$

\end{document}


You might want to add an option to your package. Remember to modify the default to what you think best given your PDF files

## scriptr.sty

\NeedsTeXFormat{LaTeX2e}[1999/12/01]
\ProvidesPackage{scriptr}[2014/06/18 Griffiths' Script r Character]
\RequirePackage{kvoptions}
\SetupKeyvalOptions{prefix=scriptr@}
\DeclareStringOption{size}
\ProcessKeyvalOptions*

\RequirePackage{graphicx}
\RequirePackage{amstext} % for \text

\newcommand\rcurs{\text{\includegraphics[height=\scriptr@size ex]{Rmed}}}
\newcommand\brcurs{\text{\includegraphics[height=\scriptr@size ex]{Rbold}}}

\endinput


## Test file

\documentclass{article}
\usepackage{amsmath}
\usepackage{scriptr}
%%% Might be as follows, for adapting to a different main font
%\usepackage[size=1.5]{scriptr}

\begin{document}

Since $\hat{\brcurs}=\brcurs/\rcurs$, we know that
$\hat{\brcurs}/\rcurs^{2}=\brcurs/\rcurs^{3}$.
Furthermore $1/\rcurs^{3}$ can be rewritten as
$\tfrac{1}{\rcurs^{3}}= \frac{1}{\rcurs^{3}}= \bigl[(x-x')^{2}+(y-y')^{2}+(z-z')^{2}\bigr]^{3/2}.$

\huge
Since $\hat{\brcurs}=\brcurs/\rcurs$, we know that
$\hat{\brcurs}/\rcurs^{2}=\brcurs/\rcurs^{3}$.
Furthermore $1/\rcurs^{3}$ can be rewritten as
$\tfrac{1}{\rcurs^{3}}= \frac{1}{\rcurs^{3}}= \bigl[(x-x')^{2}+(y-y')^{2}+(z-z')^{2}\bigr]^{3/2}.$

\end{document}

-