3

Answering this question: Overlay a 0 with a | I made this code:

\documentclass{article}
\usepackage{tikz}
\newcommand{\zerobar}{
\begin{tikzpicture}[baseline, overlay]
\node[anchor=base] {$0$};
\draw (0,0) -- (0,1.5ex);
\end{tikzpicture}
}
\begin{document}
Test in text \zerobar{} test $0$ test\\
Test in math $\zerobar{}+2=0+2$
\end{document}

Text

How do I make \zerobar behave like 0 with the correct spacing in math?

I was thinking \DeclareMathSymbol, but I am not even sure that it is used for this or that it can be used here. I do not fully understand the examples given here:

https://tex.loria.fr/ctan-doc/macros/latex/doc/html/fntguide/node18.html

or here:

https://cs.brown.edu/about/system/managed/latex/doc/amsfonts.pdf

1 Answers1

5

With help from @DavidCarlisle, I got the correct spacing with this code:

\documentclass{article}
\usepackage{tikz}
\newcommand{\zerobar}{%
\begin{tikzpicture}[baseline]
\node[anchor=base, inner sep=0] {$0$};
\draw (0,0) -- (0,1.5ex);
\end{tikzpicture}}
\begin{document}
Test in text \zerobar{} test $0$ test\\
Test in math $\zerobar{}+2=0+2$
\end{document}

Test text with correct spacing

I am still not sure, if the TikZ picture behaves in the same way as 0 in all situations regards to spacing.

  • For your final sentence: 0 has no spacing rules, it's a mathord so has teh smae spacing as the tikz box but you this will be like \mbox{$0$} which is your basic node, so it won't get smaller in subscripts, you could modify it to use \mathpallette as in the other aanswers in that question. – David Carlisle Sep 15 '21 at 06:55