I have created a few dozen macros, three of which I show here, for example.
\newcommand{\alphaactual}{$\alpha_\text{actual}$\index{a@$\alpha_\text{actual}$ (Actual Zero Sight Line Angle-Of-Attack)}}
\newcommand{\alphai}{$\alpha_\text{i}$\index{a@$\alpha_\text{i}$ (Zero Sight Line Angle-Of-Attack At Rollout)}}
\newcommand{\alphar}{$\alpha_\text{r}$\index{a@$\alpha_\text{r}$ (Zero Sight Line Angle-Of-Attack At Release)}}
From time to time, I place one of these macros inside of math mode. The following is one example of this:
$frac{\alphar}{17.45}$
Clearly, this causes an error, since it is equivalent to:
$\frac{ $\alpha_\text{r}$ }{17.45}$
I prefer to retain the opening and closing dollar signs, within the macro definition, to eliminate the need to type the dollar signs in paragraph mode.
Is there a method to persuade LaTeX to accept $frac{\alphar}{17.45}$?
Thank you.
LaTeX forum ⇒ General ⇒ Math Mode Question Topic is solved
- Stefan Kottwitz
- Site Admin
- Posts: 10068
- Joined: Mon Mar 10, 2008 9:44 pm
Math Mode Question Topic is solved
Hi Kurt,
you could use the
Stefan
you could use the
\ensuremath
command for your macros: latex2e.org/_005censuremath.htmlStefan
LaTeX.org admin
-
- Posts: 22
- Joined: Thu Feb 07, 2019 4:25 pm
Math Mode Question
Hi, Stefan.
Thank you for the elegant solution.
Regards,
Kurt
Thank you for the elegant solution.
Regards,
Kurt
-
- Posts: 2
- Joined: Mon Nov 06, 2023 1:11 pm
Math Mode Question
To achieve your desired behavior, where you want to use the dollar signs within your custom macros, you can define the macros in a way that they handle math mode appropriately. You can use the ' \ensuremath ' command to automatically switch to math mode when the macros are used in text mode. Here's how you can redefine your macros:
By using ' \ensuremath ', LaTeX will automatically switch to math mode when you use these macros inside or outside of math mode. This way, you can use them with or without the dollar signs, and LaTeX will handle the math mode appropriately.
For example, you can use them like this:
This will work as expected and eliminate the need to manually add dollar signs when using the macros.
\newcommand{\alphaactual}{\ensuremath{\alpha_\text{actual}\index{a@$\alpha_\text{actual}$ (Actual Zero Sight Line Angle-Of-Attack)}}} \newcommand{\alphai}{\ensuremath{\alpha_\text{i}\index{a@$\alpha_\text{i}$ (Zero Sight Line Angle-Of-Attack At Rollout)}}} \newcommand{\alphar}{\ensuremath{\alpha_\text{r}\index{a@$\alpha_\text{r}$ (Zero Sight Line Angle-Of-Attack At Release)}}
By using ' \ensuremath ', LaTeX will automatically switch to math mode when you use these macros inside or outside of math mode. This way, you can use them with or without the dollar signs, and LaTeX will handle the math mode appropriately.
For example, you can use them like this:
In text mode: \alphar{} is an important angle. In math mode: $\frac{\alphar}{17.45}$.
This will work as expected and eliminate the need to manually add dollar signs when using the macros.
-
- Posts: 2
- Joined: Mon Nov 06, 2023 1:11 pm
Math Mode Question
All good now? My friend was overjoyed with the outcome when I recommended this https://www.grabmyessay.com/custom-essay service to them recently. They truly stand out for their meticulous attention to detail, extensive research, and capacity for meeting deadlines. You want other people to gain from what you find beneficial. So, if you know someone struggling with essays, direct them to GrabMyEssay.
Who is online
Users browsing this forum: No registered users and 8 guests