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 package which, among other things, gives abbreviations for \mathbb, as follows:

\newcommand{\A}{\mathbb A}
\def\B{\mathbb B}
\def\C{\mathbb C}
\newcommand{\D}{\mathbb D}
\newcommand{\E}{\mathbb E}
\newcommand{\F}{\mathbb F}
\def\G{\mathbb G}
\def\H{\mathbb H}
\newcommand{\I}{\mathbb I}
\newcommand{\J}{\mathbb J}
\newcommand{\K}{\mathbb K}
\def\L{\mathbb L}
\def\M{\mathbb M}
\newcommand{\N}{\mathbb N}
\def\O{\mathbb O}
\def\P{\mathbb P}
\newcommand{\Q}{\mathbb Q}
\newcommand{\R}{\mathbb R}
\def\S{\mathbb S}
\def\T{\mathbb T}
\def\U{\mathbb U}
\newcommand{\V}{\mathbb V}
\newcommand{\W}{\mathbb W}
\newcommand{\X}{\mathbb X}
\newcommand{\Y}{\mathbb Y}
\newcommand{\Z}{\mathbb Z}
\DeclareSymbolFont{bbold}{U}{bbold}{m}{n}
\DeclareSymbolFontAlphabet{\bb}{bbold}

The reason for the \def-\newcommand oscillation is that I have seen some of those commands are not always defined, so choosing \newcommand would give problems in some cases while \renewcommand would in others, while \def bypasses this by not checking if the commands are defined or not. The strange thing which this question is about is that removing the braces from the \defs (e.g. in \def\B{\mathbb B} removing those around \mathbb B, and similarly from all the other \def commands) seems to cause problems. For example, removing them all except those of \B and \C causes:

./mworks.sty:844: LaTeX Error: \mathbb allowed only in math mode.

See LaTeX manual or LaTeX Companion for explanation.
Type G <return> for immediate help.
 ...

1.844 \newcommand{\I}{\mathbb
                               I}
?

Why does that happen?

share|improve this question
4  
It doesn't really make sense to oscillate, why make \newcommand check if you never want the check to fail? my as well use \def always. \mathbb should always have {} around its argument (like all latex commands) although you can get away without sometimes. As for the error, You know the drill please always provide a complete small document that demonstrates the problem. The error clearly shows that the \newcommand{\I} was not being executed, probably gobbled by a missing brace earlier. –  David Carlisle Apr 5 at 10:31
1  
I'm afraid it's not clear to me what your posting is about. Removing which braces, from which macros, is causing problems? Your screenshot seems to be related to the definition of \I -- which according to your setup is defined via \newcommand and not via \def; as such, it doesn't seem to be related to issues with \def. –  Mico Apr 5 at 10:35
    
@Mico you need to polish your crystal ball, the problem with \I is probably caused by mis-using \def on the line above:-) (see my answer) –  David Carlisle Apr 5 at 10:44
    
@DavidCarlisle - My crystal ball has been showing me nothing but dense fog of late. Congrats on figuring out what the cause of the reported problem was -- where do get your crystal ball polished? :-) –  Mico Apr 5 at 11:49
    
Congrats: You have essentially defined a new math language: Not LaTeX but MickGTeX. –  Martin Schröder Apr 7 at 10:48

2 Answers 2

You have probably discovered why it's very strongly discouraged to redefine kernel commands with \def.

For instance, \H is defined to give the “hungarian umlaut” accent; so, if you are talking about Erdős in your document, you'll get a puzzling error, even if you seem not to be using \H. Actually when \usepackage[utf8]{inputenc} is in force, LaTeX translates Erdős into Erd\H{o}s. Can you see the problem?

Don't redefine kernel commands unless you know precisely what you're doing. If \newcommand can't be used, you must check what the command means and, if it turns out to be a command for typesetting accents or similar things, don't redefine it.

It's also particularly bad is adding those commands in a package, even if it's for personal usage. If you pass it to your buddies, they'll start to use it and maybe include it in something they submit elsewhere. As Barbara Beeton observes in a comment,

if a package like this gets submitted with a manuscript to a publisher, it can become very expensive to correct, and may result in rejection of the manuscript.

I should add that she is a great expert (the expert, perhaps) in copy editing for journals and books at the AMS.

You can try saying

\def\box#1{\fbox{#1}}

and see what happens.

Of course, the syntax

\def{\A}{\mathbb A}

is invalid: while \newcommand{\A}{...} is good, no brace can follow \def. Irremediably wrong is also

\def\B \mathbb B

which makes really no sense. By the way, the preferred syntax would be \mathbb{B} with braces that clearly delimit what \mathbb is applied to.

share|improve this answer
3  
you should add that it is especially bad to redefine kernel commands in a package, since packages are often passed on to other people who use them blindly, and they may not be able to figure out what has gone wrong. if a package like this gets submitted with a manuscript to a publisher, it can become very expensive to correct, and may result in rejection of the manuscript. –  barbara beeton Apr 5 at 11:21

As the posted code doesn't generate the error shown, I'll modify it so it does.

This complete document demonstrates the error.

\RequirePackage{amsfonts}
\newcommand{\A}{\mathbb A}
\def\B{\mathbb B}
\def\C{\mathbb C}
\newcommand{\D}{\mathbb D}
\newcommand{\E}{\mathbb E}
\newcommand{\F}{\mathbb F}
\def\G{\mathbb G}
\def\H \mathbb H
\newcommand{\I}{\mathbb I}

\stop

it produces

$ pdflatex er11
This is pdfTeX, Version 3.1415926-2.5-1.40.14 (TeX Live 2013)
 restricted \write18 enabled.
entering extended mode
(./er11.tex
LaTeX2e <2011/06/27>
Babel <3.9j> and hyphenation patterns for 54 languages loaded.
(/usr/local/texlive/2013/texmf-dist/tex/latex/amsfonts/amsfonts.sty)

! LaTeX Error: \mathbb allowed only in math mode.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.10 \newcommand{\I}{\mathbb
                             I}
? 

the immediate fix is to make it like the code posted in the question, or as egreg notes, better don't use one-letter commands and over-write LaTeX internals.

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.