Math & Science ⇒ custom stackrel command with proper line/equation placement
custom stackrel command with proper line/equation placement
I would like to make a custom command that does
\stackrel{d}{\rightarrow}
when inside an equation, but does
\rightarrow_{d}
when (in mathmode) in a paragraph. (In order to avoid spreading lines in paragraphs.)
I know how to make very simple custom commands, but this is a step beyond my knowledge. Can anyone give me a hint of how I would go about doing this? Thanks.
\stackrel{d}{\rightarrow}
when inside an equation, but does
\rightarrow_{d}
when (in mathmode) in a paragraph. (In order to avoid spreading lines in paragraphs.)
I know how to make very simple custom commands, but this is a step beyond my knowledge. Can anyone give me a hint of how I would go about doing this? Thanks.
NEW: TikZ book now 40% off at Amazon.com for a short time.
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
custom stackrel command with proper line/equation placement
There is a command which makes LaTeX not to regard the height of the box containing your operator. Additionally you should decrease the size of the upper symbol not to make it look too bad in the line.
Best regards
Thorsten¹
Code: Select all
$x\smash{\stackrel{\scriptscriptstyle d}{\rightarrow}}y$
Best regards
Thorsten¹
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Re: custom stackrel command with proper line/equation placement
thank you, that works well for stopping the line-spreading and I think I might use that, although its not quite what I was looking for...
My idea was more along the line of how \lim works. If I use \lim_{n \rightarrow \infty} in a paragraph then the "n \rightarrow \infty" part ends up on the lower right of "lim" rather than below "lim" as it would if I used the command inside an equation environment. Do you know what the logic is that creates that and how I could apply it to this problem?
My idea was more along the line of how \lim works. If I use \lim_{n \rightarrow \infty} in a paragraph then the "n \rightarrow \infty" part ends up on the lower right of "lim" rather than below "lim" as it would if I used the command inside an equation environment. Do you know what the logic is that creates that and how I could apply it to this problem?
custom stackrel command with proper line/equation placement
Math atoms of class 1 take limits when inserted in display style:
Code: Select all
\documentclass{article}
\usepackage{amsmath}
\newcommand*\test{\mathop\rightarrow^x}
\begin{document}
$a \test b$
\begin{align*}
a \test b
\end{align*}
\end{document}
custom stackrel command with proper line/equation placement
so now i'm being quite picky, but this is partly as an interest in learning TeX better. In that one the expression appearing in the paragraph is superscripted, whereas I would prefer it to be subscripted. This seems to require some additional logic. I was trying something like this using the ifthen package:
except I can't find a TeX boolean for paragraph versus equation (there's one for mmode but that treats paragraphs and equations the same).
Code: Select all
\documentclass{article}
\usepackage{amsmath, ifthen}
\newcommand*\test{\ifthenelse{\boolean{???}}{\mathop\rightarrow^x}{\mathop\rightarrow_{x}}}
\begin{document}
$a \test b$
\begin{align*}
a \test b
\end{align*}
\end{document}
custom stackrel command with proper line/equation placement
Then you need to distinguish between the for math styles using \mathchoice:
Code: Select all
\documentclass{article}
\usepackage{amsmath}
\newcommand*\testA{\mathop{\mkern0mu\rightarrow}^x}
\newcommand*\testB{\mathchoice{\stackrel x\rightarrow}{\rightarrow_x}{\rightarrow_x}{\rightarrow_x}}
\begin{document}
$a \testA b \testB c$
\begin{align*}
&a \testA b \testB c \\
&\frac{\frac{\frac\testB\testB}\testB}\testB
\end{align*}
\end{document}
custom stackrel command with proper line/equation placement
that is excellent, thank you. This \mathchoice command is going to help me out in a lot of other regards as well. Many thanks!