3

I sometimes use tikz to draw special symbol that are then used in equation. I don't know if there is a better way to do it but it is farily easy and give good result. To give a concrete example:

\newcommand{\symb}{\tikz[baseline=(s.base)]{
        \node[inner sep=1pt,outer sep=0pt] (s) {$s$};
        \draw[-] (s.north east) -- (s.south east) -- (s.south west) -- (s.north west);
    }}

to a get a math-style s with three side of a box around it. It works well in almost all situation with one exception: it does not scale properly when used as a subscript or an exponent.

In $s$ vs $\symb$ both s have the exact same size, even if they appears in a title or with different font size, like {\Large $s$ vs $\symb$} both s still have the exact same size. But when script are involved i.e. in $X_s$ vs $X_\symb$, the second one the $s$ is not in script size.

So, is there a way to modify the command $\symb$ above, so that when used within a subscript or exponent, it gets scaled in the same way as the text does ?

I've already found a working solution: create a second version of the command to be used when in scriptstyle:

\newcommand{\symbsc}{\tikz[baseline=(s.base)]{
        \node[inner sep=1pt,outer sep=0pt] (s) {$\scriptstyle s$};
        \draw[-] (s.north east) -- (s.south east) -- (s.south west) -- (s.north west);
    }}

which produces the desired result visually, but I find it a bit annoying to have two different functions depending if I'm in scriptstyle or not. I was hopping someone could suggest me a better way to do this ?

Minimal example:

\documentclass{article}
\usepackage{tikz}

\newcommand{\symb}{\tikz[baseline=(s.base)]{
        \node[inner sep=1pt,outer sep=0pt] (s) {$s$};
        \draw[-] (s.north east) -- (s.south east) -- (s.south west) -- (s.north west);
    }}

\begin{document}

In normale size: $\symb$ vs $s$.

In large scale, it scales well: {\Large $\symb$ vs $s$ }

But in subscript, it doesn't: $X_{\symb}$ vs $X_{s}$

It especially look bad if both appear in the same subscrit:

$X_{s \symb}$ vs $s \symb$

\end{document}

enter image description here

1 Answer 1

3

Wrapping the whole \tikz thing inside \text{...} provided by amsmath package does the work. Note the \text is like \mbox if used in text mode, which does no harm in this case.

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}

\makeatletter
\newcommand{\symb}{%
  \text{%
    \tikz[baseline=(s.base)] {
      \node[inner sep=1pt, outer sep=0pt] (s) {$s$};
      \draw (s.north east) -- (s.south east) -- (s.south west) -- (s.north west);
    }%
  }%
}
\makeatother

\begin{document}

In normale size: $\symb$ vs $s$.

In large scale, it scales well: {\Large $\symb$ vs $s$ }

But in subscript, it doesn't: $X_{\symb}$ vs $X_{s}$

It especially look bad if both appear in the same subscrit:

$X_{s \symb}$ vs $s \symb$

\end{document}

enter image description here

3
  • Thanks, that is a very neat trick ! For the record, I'm quite curious of why this works, but I'm very happy with it. Aug 19, 2020 at 15:49
  • Ah I think I got it: when used in subscript or exponent, \text{} has the effect of modifying the current fontsize, while \subscriptstyle apparently works differently: \makeatletter $X_{\f@size}$ and $X_\text{\f@size}$ display different font size. Aug 19, 2020 at 16:13
  • @SimonHenry The current font size is only changeable in text mode, so one need to switch to text mode, change font size, then typeset text as if they are in desired math style (text, subscript, or subsubscript style). Running texdoc amstext will (normally) open the doc of amstext package which contains a documented implementation of \text in detail. Aug 19, 2020 at 23:46

You must log in to answer this question.

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