3

I'm working on a Swedish language file to fmtcount and, to support some of fmtcount's commands (e.g. \Numberstring and NUMBERstring), I need to make strings containing the Swedish characters å, ä and ö uppercase. This seems unproblematic with XeTeX and LuaTeX, but not so much in pdfTeX.

The macro level

A full version of what I want to do that involves as little of my LaTeX fumbling as possible would be the example below. As my own language file is based on the German language file (fc-german.def), I here make a minimal change to that file to highlight the problem, which leads to the compilation with pdfTeX simply not finishing. Without my change the document reads "Acht" and with my change I had hoped that it would read "Åtta".

\documentclass[german]{article}
% \usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage{fmtcount}
\FCloadlang{german}
\makeatletter
% Redefine code from fc-german.def
\renewcommand*\@@unitstringgerman[1]{%
  \ifcase#1%
    null%
    \or ein%
    \or zwei%
    \or drei%
    \or vier%
    \or f\"unf%
    \or sechs%
    \or sieben%
    \or åtta% Changed from "acht" to "åtta"
    \or neun%
  \fi
}%
\global\let\@@unitstringgerman\@@unitstringgerman
\makeatother
\begin{document}
  \newcounter{mycounter}
  \setcounter{mycounter}{8} \themycounter\ \Numberstring{mycounter}\\
\end{document}
  • If I uncomment \usepackage[T1]{fontenc}, then the compilation still does not finish.
  • If I write {\aa}tta instead of åtta, then the compilation crashes.
  • If I write {\aa}tta instead of åtta and uncomment \usepackage[T1]{fontenc}, then the compilation again does not finish.

My fumbling attempt to approach the micro level

I think that this example has the same problem as the macro level one. It at least sure behaves the same way. (It is probably very related to my last question.)

\documentclass{article}
% \usepackage[T1]{fontenc}
\makeatletter
\newcommand*\@@unitstringgerman[1]{%
  \ifcase#1%
    null%
    \or ein%
    \or zwei%
    \or drei%
    \or vier%
    \or f\"unf%
    \or sechs%
    \or sieben%
    \or åtta% Changed from "acht" to "åtta"
    \or neun%
  \fi
}%
\usepackage{etoolbox}
\newcommand*{\zz}{% Supposed to make the first letter of `\@@unitstringgerman{8}` (i.e. "åtta") uppercase
  \def\one{}%
  \def\two{}%
  \eappto\two{\@@unitstringgerman{8}}%
  \edef\one{\noexpand\MakeUppercase\expandonce\two}%
  \one%
}
\makeatother
\begin{document}
  \zz
\end{document}
  • If I uncomment \usepackage[T1]{fontenc}, then the compilation still does not finish.
  • If I write {\aa}tta instead of åtta, then the compilation crashes.
  • If I write {\aa}tta instead of åtta and uncomment \usepackage[T1]{fontenc}, then the compilation again does not finish.

2 Answers 2

4

Titlecasing is best left to the proper command. With a reasonably up-to-date LaTeX:

\documentclass{article}
\usepackage[T1]{fontenc}
\makeatletter
\newcommand*\@@unitstringgerman[1]{%
  \ifcase#1%
    null%
    \or ein%
    \or zwei%
    \or drei%
    \or vier%
    \or f\"unf%
    \or sechs%
    \or sieben%
    \or åtta% Changed from "acht" to "åtta"
    \or neun%
  \fi
}%
\begin{document}
  \makeatletter
  \MakeTitlecase{\@@unitstringgerman{8}}
  \makeatother
\end{document}

(The 'classical' approach of grabbing only one token using \MakeUppercase will fail with 8-bit engines and non-ASCII input, quite apart from the small number of cases where uppercasing and titlecasing are different.)

2
  • I wasn't aware of \MakeTitlecase. Surprisingly, it behaves as titlecasing is done in Swedish, i.e. it just uppercases the very first letter. I would have thought that it would take a (completely arbitrary) title such as "Electronic control of the protonation rates of Fe-Fe bonds" and turn it into "Electronic Control of the Protonation Rates of Fe-Fe Bonds". Is there anywhere I could read about it?
    – Fredrik P
    Commented Feb 16, 2023 at 8:39
  • 2
    It's in LaTeX News, or usrguide; 'titlecase' is the Unicode term for changing the first 'character' only of a string: applying it to every word would be a higher-level function
    – Joseph Wright
    Commented Feb 16, 2023 at 9:16
0

This answer incorporates mostly the insight from Joseph's answer into the examples in the original question for the benefit of posterity (as my edit of his answer wasn't accepted).

Micro level

The edited example works as intended, but some confusion remains.

  • If I uncomment \usepackage[T1]{fontenc}, then nothing changes.
  • If I write {\aa}tta instead of åtta, then the compilation crashes.
  • If I write {\aa}tta instead of åtta and uncomment \usepackage[T1]{fontenc}, then the compilation again does not finish.
\documentclass{article}
% \usepackage[T1]{fontenc}
\makeatletter
\newcommand*\@@unitstringgerman[1]{%
  \ifcase#1%
    null%
    \or ein%
    \or zwei%
    \or drei%
    \or vier%
    \or f\"unf%
    \or sechs%
    \or sieben%
    \or åtta% Changed from "acht" to "åtta"
    \or neun%
  \fi
}%
\usepackage{etoolbox}
\newcommand*{\zz}{% Supposed to make the first letter of `\@@unitstringgerman{8}` (i.e. "åtta") uppercase
  \def\one{}%
  \def\two{}%
  \eappto\two{\@@unitstringgerman{8}}%
  % \edef\one{\noexpand\MakeUppercase\expandonce\two}%
  \edef\one{\MakeTitlecase{\two}}%
  \one%
}
\makeatother
\begin{document}
  \zz
\end{document}

Macro level

The macro level example also works as intended and behaves the same as the micro example to the permutations.

\documentclass[german]{article}
% \usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage{fmtcount}
\FCloadlang{german}
\makeatletter
% Redefine code from fc-german.def
\renewcommand*\@@unitstringgerman[1]{%
  \ifcase#1%
    null%
    \or ein%
    \or zwei%
    \or drei%
    \or vier%
    \or f\"unf%
    \or sechs%
    \or sieben%
    \or åtta% Changed from "acht" to "åtta"
    \or neun%
  \fi
}%
\global\let\@@unitstringgerman\@@unitstringgerman
\renewcommand*{\@NumberstringMgerman}[2]{%
  \@numberstringMgerman{#1}{\@@num@str}%
  \edef#2{\MakeTitlecase{\@@num@str}}%
}%
\makeatother
\begin{document}
  \newcounter{mycounter}
  \setcounter{mycounter}{8} \themycounter\ \Numberstring{mycounter}\\
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .