7

This is a follow-up question to this one: How can I get a "divide by" symbol with \usepackage{physics}? In the referenced question the OP asked how to \undef a redefined \div. I want to reinvent the wheel, and see the exact "source code" what is used to render \div in the first place. But where do I find it?

Here is a MNWE:

\documentclass{article}
\begin{document}
What is the \emph{exact} ``source code'' of
\ttfamily\textbackslash div\normalfont, and
where do I find it? Whatever it is, it renders
this: $\div$. I want to use it as a 
starting-point to \ttfamily\textbackslash
def \normalfont my own variant 
\ttfamily\textbackslash mydiv\normalfont.
\end{document}

Bonus question: how do I write \ttfamily \textbackslash (the MNWE above gives me a warning about "font shapes not available").

2
  • 2
    Try \show\div
    – Joseph Wright
    Commented Jun 8, 2016 at 10:07
  • 2
    At least for you MNWE, you can get the ttfamily backslash with \verb|\def| Commented Jun 8, 2016 at 10:20

2 Answers 2

5

Assuming TeX Live on a Unix system with bash, open a terminal window and type

texdef -t latex div

and return. You'll get the following info:

> texdef -t latex div

\div:
\mathchar"2204


\the\div:
8708

that's not really so much interesting, perhaps, for the non cognoscenti. The same information would be issued by doing \show\div in an interactive session or by typing

\texttt{\meaning\div}

in a document and typesetting it.

However, being \div a core math symbol, the real definition can be found in fontmath.ltx; type

grep '\\div\b' $(kpsewhich fontmath.ltx)

and the terminal will print

\DeclareMathSymbol{\div}{\mathbin}{symbols}{"04}

which is indeed the definition the LaTeX kernel does of \div.

You find all the core math symbols definitions by doing something like

less $(kpsewhich fontmath.ltx)
5
  • all the math symbol definitions? no, only the "basic" ones that came with the original tex. there are a lot more in, e.g., amsfonts and amssymb and other "add-on" symbol packages. Commented Jun 8, 2016 at 14:45
  • @barbarabeeton I added ”core“; it's generally complicated to find the definitions for other symbols. The ”comprehensive list“ helps in finding the package involved, but then it may make rather cryptic definitions.
    – egreg
    Commented Jun 8, 2016 at 14:54
  • thanks for update. i agree with everything else. (and having had to track down lots of symbol definitions, because they're not necessarily the same with different fonts, i definitely sympathize with anyone else who has to do it.) Commented Jun 8, 2016 at 14:58
  • @barbarabeeton The best is MnSymbol, where the slot numbers are implicit and you have to count lines.
    – egreg
    Commented Jun 8, 2016 at 15:08
  • mathabx is only a little above that; with three fonts, it takes a little digging to figure out which one is relevant. but you're right about MnSymbol. Commented Jun 8, 2016 at 15:10
2

The OP states that "I want to reinvent the wheel..."

I would note that, to make your own personal version of \div, one does not necessarily have to know the exact formulation of the original. In particular, the code

\let\svdiv\div
\def\div{...\svdiv...}

will allow a new \div to be defined in terms of the original. Furthermore, in the case of \div, as Joseph noted in a comment, \show\div reveals the definition as \mathchar"2204 indicating there is no "code" per se for the division sign, but rather it merely points to a glyph slot of the font intself (slot 4 of the math symbol font).

\documentclass{article}
\usepackage{stackengine}
\begin{document}
Here is the new \textbackslash div:
\let\svdiv\div
\def\div{\mathbin{\ensurestackMath{\stackinset{c}{.002ex}{c}{-.06ex}{\circ}{\svdiv}}}}
$A \div B$
\end{document}

enter image description here

If one did not wish to redefine the original, but only to define \mydiv in terms of the original, then this:

\documentclass{article}
\usepackage{stackengine}
\begin{document}
Here is \textbackslash mydiv:
\def\mydiv{\mathbin{\ensurestackMath{\stackinset{c}{.002ex}{c}{-.06ex}{\circ}{\div}}}}
$A \mydiv B$
\end{document}
0

You must log in to answer this question.

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