3

Why does the code

\documentclass{memoir}
\usepackage[latin1]{inputenc}
\usepackage[danish]{babel}
\usepackage[T1]{fontenc}
\def£#1£{``#1''}
\def€#1€{<#1>}
\begin{document}
Hi, £this£ is nice, and €this€ is beautiful
\end{document}

work, while the code

\documentclass{memoir}
\usepackage[latin1]{inputenc}
\usepackage[danish]{babel}
\usepackage[T1]{fontenc}
\def /#1/{``#1''}
\def this #1 crashes{<#1>}
\begin{document}
Hi, /this/ is nice, and this this crashes is beautiful
\end{document}

does not?

4
  • 2
    In your first example € is an active char (a "one-letter" command) and you are redefining it. In your second example there is no command which can be defined after the \def. Jun 6 '14 at 8:56
  • 1
    Note also that you can omit the line \def this #1 crashes{<#1>} from your second example, and still get the same error behaviour. Jun 6 '14 at 9:06
  • 1
    Note that even the case that appears to work shouldn't be used, as while it sort of half works in latin1 (or really 15 as it has euro) if you save the file as utf-8 and use [utf8] then you can not do that at all, as the definition would make whole blocks of characters be an error (any character with the same leading byte) Jun 6 '14 at 11:30
  • Not even if you make the characters active? Is there no way to use such command notation properly? For it could really come in handy sometimes.
    – Gaussler
    Jun 6 '14 at 12:56
2

The problem is that £ and are active characters, and hence amenable to being \defined. The / character isn't. To make it so, you can adjust its catcode to make it active. The following works out fine.

\documentclass{memoir}
\usepackage[latin1]{inputenc}
\usepackage[danish]{babel}
\usepackage[T1]{fontenc}
\catcode`/=13
\def /#1/{``#1''}
\begin{document}
/this/
\end{document}

The second part of your second example doesn't make sense, since this and crashes are not single characters. Even if you reduced them to a single alphabetic character, you'd still be in dangerous territory. The following, for instance, works:

\documentclass{memoir}
\usepackage[latin1]{inputenc}
\usepackage[danish]{babel}
\usepackage[T1]{fontenc}
\catcode`q=13
\def q#1q{``#1''}
\begin{document}
qgq
\end{document}

but if you do the same with d instead of q

\catcode`d=13

then you suddenly aren't able to use the \def command anymore, since it contains a d!

3
  • 1
    But why are exactly the currency symbols active? Are they being used for something?
    – Gaussler
    Jun 6 '14 at 10:11
  • 2
    @Gaussler: When you load inputenc all non-ascii chars are active. Jun 6 '14 at 10:43
  • 1
    Just don't try that first example with [utf8] :-) Jun 6 '14 at 11:56

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.