6

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

6

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
  • $\m@th\mathbf{#1}$? – Henri Menke Jan 5 '16 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.

  • \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 '16 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 '16 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 '16 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. – Henri Menke Jan 5 '16 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.