LaTeX forum ⇒ GeneralMath Mode Question Topic is solved

LaTeX specific issues not fitting into one of the other forums of this category.
kurttodoroff
Posts: 22
Joined: Thu Feb 07, 2019 4:25 pm

Math Mode Question

Postby kurttodoroff » Tue Oct 31, 2023 12:37 am

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.

Recommended reading 2021:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics
User avatar
Stefan Kottwitz
Site Admin
Posts: 10068
Joined: Mon Mar 10, 2008 9:44 pm

Math Mode Question  Topic is solved

Postby Stefan Kottwitz » Tue Oct 31, 2023 11:51 am

Hi Kurt,

you could use the \ensuremath command for your macros: latex2e.org/_005censuremath.html

Stefan
LaTeX.org admin

kurttodoroff
Posts: 22
Joined: Thu Feb 07, 2019 4:25 pm

Math Mode Question

Postby kurttodoroff » Tue Oct 31, 2023 2:32 pm

Hi, Stefan.

Thank you for the elegant solution.

Regards,

Kurt

LouisMyers
Posts: 2
Joined: Mon Nov 06, 2023 1:11 pm

Math Mode Question

Postby LouisMyers » Mon Nov 06, 2023 1:16 pm

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:
\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.

LouisMyers
Posts: 2
Joined: Mon Nov 06, 2023 1:11 pm

Math Mode Question

Postby LouisMyers » Mon Nov 20, 2023 10:02 am

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.


Return to “General”

Who is online

Users browsing this forum: No registered users and 8 guests