8

I would like a macro that takes a single argument, makes the argument bold, rotates it by -90 degrees around its center, and automatically scales it to the correct font size depending on where it is used. The macro will be used exclusively in math mode.

As you can see in the output of the MWE, the font size of the subscript using the \rot{0} command is too large. How can I fix this issue to get the correct font size?

MWE

\documentclass{article}

\usepackage{amsmath,graphicx}

\newcommand{\std}[1]{\mathbf{#1}}
\newcommand{\rot}[1]{\mathbin{\rotatebox[origin=c]{-90}{$\mathbf{#1}$}}}

\begin{document}%

$\std{0}, ~ \rot{0}, ~ x_\std{0}, ~ x_{\rot{0}}$

\end{document}%

Output MWE

Output MWE

3 Answers 3

8

In these cases it's much easier if you use \text:

\documentclass{article}

\usepackage{amsmath,graphicx}

\newcommand{\rot}[1]{%
  \text{\rotatebox[origin=c]{-90}{$\mathbf{#1}$}}%
}

\begin{document}

$\rot{0}, x_{\rot{0}}$

$\rot{1}, x_{\rot{1}}$

$\rot{8}, x_{\rot{8}}$

\end{document}

This hides \mathpalette in a user friendly way.

enter image description here

A possible refinement is to do

\newcommand{\rot}[1]{%
  \text{%
    \setlength{\mathsurround}{0pt}%
    \rotatebox[origin=c]{-90}{$\mathbf{#1}$}%
  }%
}

in order to be on the safe side if some document class sets the math surround parameter.

It's briefer with

\makeatletter
\newcommand{\rot}[1]{%
  \text{\m@th\rotatebox[origin=c]{-90}{$\mathbf{#1}$}}%
}
\makeatother
1
  • $\m@th\mathbf{#1}$? Jan 5, 2016 at 11:06
0

After some more searching, I came across this post, which explains in detail how it should be done. I had to change the definition of \rot to

\newcommand{\rot}[1]{{\mathpalette{\rott{#1}}\relax}}
\newcommand{\rott}[3]{\rotatebox[origin = c]{-90}{$#2\mathbf{#1}$}}

Now it seems to work correctly.

4
  • \rott is invoked by \rot with only 1 argument, yet it is defined as taking 3 arguments (of which only two appear to be used).
    – Mico
    Jan 5, 2016 at 9:05
  • By using three arguments, we gobble the \relax that was used in the \mathpalette, which is essentially a \mathchoice command, as I understand it. See the explanation in the post I mentioned for more details.
    – Ritz
    Jan 5, 2016 at 9:10
  • 1
    This is overcomplicated. You create dummy parameter \relax and use unused #3 parameter. The standard way of doing this is: \def\rot#1{{\mathpalette\rott{#1}}} \def\rott#1#2{\rotating-box{$#1\bf#2$}}
    – wipet
    Jan 5, 2016 at 10:46
  • 1
    @wipet's code is obviously meant for plain TeX. If you want to implement his suggestion in LaTeX, use \mathbf{#2} instead of \bf#2. Jan 5, 2016 at 11:06
0

This can be simply accomplished by using the \ThisStyle{...\SavedStyle...} feature of the scalerel package.

\documentclass{article}

\usepackage{amsmath,graphicx,scalerel}

\newcommand{\std}[1]{\mathbf{#1}}
\newcommand{\rot}[1]{\ThisStyle{\mathbin{\rotatebox[origin=c]{-90}{$\SavedStyle\mathbf{#1}$}}}}

\begin{document}%

$\std{0}, ~ \rot{0}, ~ x_\std{0}, ~ x_{\rot{0}}$

\end{document}%

enter image description here

You must log in to answer this question.

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