3

I was trying to write a simple class and have the following issue: I need to write some text containg German quotation marks that is staic and thus should be typeset by the class by default.

You can see in the MWE below that inside the document environment I can use "` and "' to achieve the correct markings. In the class file it does not work. I can only use \glqq and \grqq to get ir right.

Is there a way to get it up correctly or is it simply impossible without the explicit macros in class files?

Here comes the myclass.cls file:

\LoadClass[a4paper,10pt]{scrartcl}
\RequirePackage[ngerman]{babel}
\newcommand{\abc}{"`abc"' \glqq abc \grqq}

And here comes the main tex file:

\documentclass{myclass}
\begin{document}
"`abc"' \glqq abc \grqq

\abc
\end{document}
  • This has already appeared: http://tex.stackexchange.com/questions/34670/babel-shorthand-doesnt-work-in-macros – egreg Aug 01 '14 at 09:04
  • In a class you should use the non shorthand based form; and, in my opinion, no class should load babel. – egreg Aug 01 '14 at 09:07
  • I agree, but this is some sort of form to be typeset that I just manually copied from a Word document. Thus it's clear that it has to be written in German. OK, I see what I would had to do to get it working. For now I used a repacement with the non-shorthand form. This works for sure. – Christian Wolf Aug 01 '14 at 09:15

1 Answers1

2

The latest version of babel allows the option KeepShorthandsActive, so you could say

\LoadClass[a4paper,10pt]{scrartcl}
\RequirePackage[KeepShorthandsActive,ngerman]{babel}
\newcommand{\abc}{"`abc"'}

but this opens the way to several problems, because packages loaded in the preamble will be affected by the active ".

You could use

\shorthandon{"}
\newcommand{\abc}{"`abc"'}
\shorthandoff{"}

as suggested in babel shorthand "| doesn't work in macros but you can exploit the fact of being in a class file and so of being able to use @-commands. The list of shorthands is found in ngermanb.ldf

\declare@shorthand{ngerman}{"a}{\textormath{\"{a}\allowhyphens}{\ddot a}}
\declare@shorthand{ngerman}{"o}{\textormath{\"{o}\allowhyphens}{\ddot o}}
\declare@shorthand{ngerman}{"u}{\textormath{\"{u}\allowhyphens}{\ddot u}}
\declare@shorthand{ngerman}{"A}{\textormath{\"{A}\allowhyphens}{\ddot A}}
\declare@shorthand{ngerman}{"O}{\textormath{\"{O}\allowhyphens}{\ddot O}}
\declare@shorthand{ngerman}{"U}{\textormath{\"{U}\allowhyphens}{\ddot U}}
\declare@shorthand{ngerman}{"e}{\textormath{\"{e}}{\ddot e}}
\declare@shorthand{ngerman}{"E}{\textormath{\"{E}}{\ddot E}}
\declare@shorthand{ngerman}{"i}{\textormath{\"{\i}}%
                              {\ddot\imath}}
\declare@shorthand{ngerman}{"I}{\textormath{\"{I}}{\ddot I}}
\declare@shorthand{ngerman}{"s}{\textormath{\ss}{\@SS{}}}
\declare@shorthand{ngerman}{"S}{\SS}
\declare@shorthand{ngerman}{"z}{\textormath{\ss}{\@SS{}}}
\declare@shorthand{ngerman}{"Z}{SZ}
\declare@shorthand{ngerman}{"`}{\glqq}
\declare@shorthand{ngerman}{"'}{\grqq}
\declare@shorthand{ngerman}{"<}{\flqq}
\declare@shorthand{ngerman}{">}{\frqq}
\declare@shorthand{ngerman}{"-}{\nobreak\-\bbl@allowhyphens}
\declare@shorthand{ngerman}{"|}{%
  \textormath{\penalty\@M\discretionary{-}{}{\kern.03em}%
              \allowhyphens}{}}
\declare@shorthand{ngerman}{""}{\hskip\z@skip}
\declare@shorthand{ngerman}{"~}{\textormath{\leavevmode\hbox{-}}{-}}
\declare@shorthand{ngerman}{"=}{\penalty\@M-\hskip\z@skip}

so, for instance, instead of "a in a class macro, you can say \"{a}\allowhyphens and, instead of "- you can use

\nobreak\-\bbl@allowhyphens

Note that the \textormath alternative is useless in a class macro wanting to use "a.

Probably babel should use an indirect method (there are much less memory problems nowadays). In my opinion it should say

\def\bbl@ngerman@quotehyphen{\nobreak\-\bbl@allowhyphens}

and then

\declare@shorthand{ngerman}{"-}{\bbl@ngerman@quotehyphen}

For "a it should have

\def\bbl@ngerman@quotea@text{\"{a}\allowhyphens}
\def\bbl@ngerman@quotea@math{\ddot a}

and

\declare@shorthand{ngerman}{"a}{%
  \textormath{\bbl@ngerman@quotea@text}{\bbl@ngerman@quotea@math}%
}

This would allow class writers to access more easily and clearly the nonshorthand version.

egreg
  • 1,121,712