10

I'm writing a set of notes for my students on trigonometry. At present, they have not met radians, which comes next year. I would like to use the same set of notes for them, but this year, give them the notes using degrees, with next years in radians. At present, I have am using (with the ifthen) package:

\newcommand{\hsc}[1]
{
\ifnum#1=0
$0^{\circ}\leq x\leq 90^{\circ}$
\else
$0\leq x\leq\frac{\pi}{2}$
\fi
}
\newcommand{\dom}[1]
{
\ifnum#1=0
$0^{\circ}\leq x\leq 360^{\circ}$
\else
$0\leq x\leq 2\pi$
\fi
}

This works well in each line I need to change, but is there a way I can insert a switch in the preamble so that these changes are made globally?

1

3 Answers 3

6

Instead of an optional argument in your commands, use a boolean declaration:

\documentclass{article}
\newif\ifdegrees
\degreestrue
\def\hsc{\ifdegrees\ensuremath{0^{\circ}\leq x\leq 90^{\circ}}
         \else\ensuremath{0\leq x\leq\frac{\pi}{2}}\fi}
\def\dom{\ifdegrees\ensuremath{0^{\circ}\leq x\leq 360^{\circ}}
         \else\ensuremath{0\leq x\leq 2\pi}\fi}

\begin{document}
    \hsc, \dom

    \degreesfalse
    \hsc, \dom
\end{document}

degreesorradians

2
  • I don't think you should be using \ensuremath here. See tex.stackexchange.com/questions/34830/….
    – jub0bs
    Apr 20, 2014 at 9:38
  • I use \ensuremath because, in my opinion, these commands must be used in math mode, but the original definition from user10082 requires text mode. Apr 20, 2014 at 11:19
4

Define a conditional and an \ANG command with two arguments; the first is used for radians, the second one for degrees; you can also define as many abbreviations as you want.

Note that in a “real” document you wouldn't switch between \radianstrue or \radiansfalse. Or maybe you'd want to; in that case some trick can be devised for allowing a “local” choice.

\documentclass{article}
\newif\ifradians
%\radianstrue % uncomment if you want angles in radians

\DeclareRobustCommand{\ANG}[2]{\ifradians#1\else#2^{\circ}\fi}
\newcommand{\Aright}{\ANG{\pi/2}{90}}
\newcommand{\Aoctant}{\ANG{\pi/4}{45}}

\begin{document}

$\ANG{0}{0}\le\alpha\le\ANG{2\pi}{360}$

Half right angle is $\Aoctant$.

\radianstrue % just for showing the effect

$\ANG{0}{0}\le\alpha\le\ANG{2\pi}{360}$

Half right angle is $\Aoctant$.

\end{document}

enter image description here

4

I am using the etoolbox package, which uses an easier syntax, in my point of view

\documentclass{book}

\usepackage{etoolbox}

%\usepackage{ifthen}


\newbool{UseRadians}
\setbool{UseRadians}{false}

\newcommand{\EnableUseRadians}{%
\setbool{UseRadians}{true}}%


\newcommand{\DisableUseRadians}{%
\setbool{UseRadians}{false}}%



\EnableUseRadians  % Enable Radians in preamble

\newcommand{\hsc}{
\ifboolexpr{not (bool{UseRadians})}{
$0^{\circ}\leq x\leq 90^{\circ}$
}{

$0\leq x\leq\frac{\pi}{2}$
}% End of use radians
}


\newcommand{\dom}{%

\ifboolexpr{not (bool{UseRadians})}{

$0^{\circ}\leq x\leq 360^{\circ}$
}{
$0\leq x\leq 2\pi$
} % End of use radians
}


\begin{document}


Now using Radians \par
\EnableUseRadians
\hsc
\dom

Now using degrees \par
\DisableUseRadians
\hsc

\dom


\end{document}

One may object the conditional inside of the commands, leading to continous queries about the state of the variable \UseRadians each time the commands are called, but the advance is to be able to switch into the relevant mode any time.

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .