Math & Science ⇒ custom stackrel command with proper line/equation placement
custom stackrel command with proper line/equation placement
\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.
Learn LaTeX easily with newest books:
The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis
The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more
LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
custom stackrel command with proper line/equation placement
Code: Select all
$x\smash{\stackrel{\scriptscriptstyle d}{\rightarrow}}y$Best regards
Thorsten¹
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Re: custom stackrel command with proper line/equation placement
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
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
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
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}