Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
    
You might find this discussion helpful: tex.stackexchange.com/questions/5894/… –  Paul Stanley Apr 20 at 8:46

3 Answers 3

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

share|improve this answer
    
I don't think you should be using \ensuremath here. See tex.stackexchange.com/questions/34830/…. –  Jubobs Apr 20 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. –  Robert Fuster Apr 20 at 11:19

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

share|improve this answer

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

\documentclass{scrbook}

\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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.