7

I have the following problem. In my document, I defined a new command to save a few chars

\renewcommand{\r}{r_\mathrm{max}}

Additionally, since it is Swedish, it makes use of the special char å, which is actually given by \aa in LaTeX . However, my newly defined command somehow seems to destroy the command \aa. I get the message that a missing $ was inserted and than the \aa somehow seems to get replaced by the r_max.

I assume the problem is that \r is already that circle above, and that's why it gets messed up. Unfortunately, my thesis is already done (except for the Swedish abstract), and I used \r quite often, so I would prefer to not change it everywhere. Is there a solution for my problem?

Here is a complete non-working example:

\documentclass[11pt]{amsart}
\usepackage{geometry}                % See geometry.pdf to learn the layout options. There are lots.
\geometry{letterpaper}                   % ... or a4paper or a5paper or ... 
\usepackage{graphicx}
\usepackage{amssymb}
\usepackage{epstopdf}
\renewcommand{\r}{r_\mathrm{max}}
\usepackage[latin1]{inputenc}
\usepackage[swedish,english]{babel}
\title{Brief Article} 
\author{The Author}
\begin{document}
\maketitle

asdasds $\r$ \aa

\end{document}  
  • Typing \show\aa shows that \aa is defined as \r a which is causing the problem. I'm not sure how you can maintain your use of \r however. – Scott H. Jun 26 '13 at 18:59
  • I didn't know that \aa was the same as \r a. Is there some similar transiteration for \l? If so, I'd like to know what it is. – Steven B. Segletes Jun 26 '13 at 19:00
  • You may want to take a look at Redefine underscore to produce roman subscript for a way to type r_{max} and get the same result as if you had typed r_\mathrm{max} (that could be helpful if you also need to typeset other variable names with roman subscripts). – Jake Jun 26 '13 at 19:13
  • 1
    Apart from the real issue (redefining \r), I suggest not using such shorthands: \rmax would be a better choice from a semantic point of view (and is not much more difficult to type). – egreg Jun 26 '13 at 19:22
  • search/replace in your editor should allow changing painlessly \r into the \rmax of egreg for example. – user4686 Jun 26 '13 at 19:46
9

I strongly recommend not to redefine such basic macros like \accents. This causes trouble such as you has experienced.

If \aa and \AA are the only macros that use the ring accent \r, then you can redefine them. Our example file uses font encoding OT. The line below would be used for encoding T1.

\DeclareTextAccent{\ring}{OT1}{23}
% \DeclareTextAccent{\ring}{T1}{6}
\renewcommand*{\aa}{\ring a}
\renewcommand*{\AA}{\ring A}

\r is also used, if å is directly used (option latin1 for package inputenc). Assuming that you are not changing the encoding, this can be fixed:

\usepackage[latin1]{inputenc}
\DeclareInputText{197}{\r A}
\DeclareInputText{229}{\r a}

Complete example:

\documentclass[11pt]{amsart}
\usepackage{geometry}                % See geometry.pdf to learn the layout op
\geometry{letterpaper}                   % ... or a4paper or a5paper or ...
\usepackage{graphicx}
\usepackage{amssymb}
\usepackage{epstopdf}
\renewcommand{\r}{r_\mathrm{max}}

\DeclareTextAccent{\ring}{OT1}{23}
\renewcommand*{\aa}{\ring a}
\renewcommand*{\AA}{\ring A}

\usepackage[latin1]{inputenc}
\DeclareInputText{197}{\r A}
\DeclareInputText{229}{\r a}

\usepackage[swedish,english]{babel}
\title{Brief Article}
\author{The Author}
\begin{document}
\maketitle

asdasds $\r$ \aa

\end{document}

Result

  • Great, that works, thank you. I obviously will not use such short commands anymore. I just didn't know that \r was actually already used. And since it is a complete thesis with over 100 pages, replacing all \r's and checking if it was correctly done would have been a lot of work. So you really saved me some time, thanks – Chris Jun 26 '13 at 20:11
  • @Chris You have \renewcommand{\r}{...}, so you knew that \r is already defined. As a general rule, never use \renewcommand if you don't know what the already defined command does. My usual example is \renewcommand{\fi}{...}: the number of errors will amaze you. – egreg Jun 26 '13 at 22:06
1

If you look into LaTeX kernel latex.ltx, you will find there the lines

\def \aa {\r a}
\def \AA {\r A}

As you see, ring accent (\r) is used in the definition of \aa and \AA.

It is a bad idea to renew LaTeX commands. You may want to define \myr instead. Just use your text editor to change \r to \myr.

0

Since the LaTeX kernel latex.ltx has the lines

\def \aa {\r a}
\def \AA {\r A}

you need to do something like

\let\ringaccent\r
\def\aa{\ringaccent a}
\def\aa{\ringaccent a}

before you redefine \r.

I disagree with the opinion that it is quite generally a bad idea to overwrite plain TeX or LaTeX commands. In math typing, you may have excellent reasons to use one-letter macros like \r or \v. Reserving them for rarely or never used accents would be wasteful. Reserving them for just two lines of LaTeX internals would be ridiculous. TeX was meant to give us flexibility; let's use it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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