2

I'm trying to use \aa in an \eappto command. The minimal code below works just fine in XeLaTeX and LuaLaTeX but fails with pdfLaTeX unless I include the fontenc package. This confuses me as \aa works perfectly outside of the \eappto command also without the fontenc package.

\documentclass{article}
% \usepackage[T1]{fontenc}
\usepackage{etoolbox}
\makeatletter
\newcommand{\zz}{%
  \def\@tmp{}%
  \eappto\@tmp{\aa}%
  \@tmp%
}
\makeatother
\begin{document}
  \aa tta% works just fine
  \zz% only works with `fontenc`
\end{document}
0

2 Answers 2

4

you should always use T1 enoding for Swedish in pdflatex, or hyphenation will be wrong, also you can not in general apply \edef to latex constructs. That said utf-8 characters are \protected so safe in an \edef so if you really want this, simply use å rather than \aa.

\documentclass{article}
% \usepackage[T1]{fontenc}
\usepackage{etoolbox}
\makeatletter
\newcommand{\zz}{%
  \def\@tmp{}%
  \eappto\@tmp{å}%
  \@tmp%
}
\makeatother
\begin{document}
  \aa tta % works just fine
  \zz tta    % only works with `fontenc`
\end{document}

enter image description here

If you have an old latex you can use the standard latex \protected@edef rather than rely on unsupported edef use.

\documentclass{article}
% \usepackage[T1]{fontenc}
\usepackage{etoolbox}
\makeatletter
\newcommand{\zz}{%
  \def\@tmp{}%
  \protected@edef\@tmp{\@tmp å}%
  \@tmp%
}
\makeatother
\begin{document}
  \aa tta % works just fine
  \zz tta    % only works with `fontenc`
\end{document}
4
  • This doesn't compile for me with pdfLaTeX.
    – Fredrik P
    Feb 13, 2023 at 7:22
  • 1
    you must have an old latex release, what version do you have? Feb 13, 2023 at 8:11
  • pdfTeX 3.141592653-2.6-1.40.23 (TeX Live 2021/W32TeX)
    – Fredrik P
    Feb 13, 2023 at 8:34
  • 1
    @FredrikP I added a version for that Feb 13, 2023 at 9:23
5

The definition of \aa is

\r a

The definition of \r with XeLaTeX or LuaLaTeX is

\TU-cmd \r \TU\r

and we can see that the definition of \TU\r (which is a strange command with a backslash in its name) is

#1->\@text@composite \TU\r #1\@empty \@text@composite {\add@unicode@accent {"030A}{#1}}.

and \r a turns out to expand to the single Unicode character å.

With the default OT1 encoding in pdflatex, the \r command becomes a complicated construction aimed to add the ring accent above the a, which doesn't survive the \edef used by \eappto.

On the other hand, with T1 the situation is similar to the previous one, because T1 encoded fonts have a precomposed å character.

However, I'd not recommend using such encoding dependent commands in \edef under any circumstance.

7
  • Is there any alternative? I need to append the word "åtta" to \@tmp
    – Fredrik P
    Feb 12, 2023 at 22:17
  • @FredrikP Is there any reason for using \eappto instead of \appto? But perhaps there are even better methods. Please try and be clearer about your real problem.
    – egreg
    Feb 12, 2023 at 22:18
  • In the less minimal code (a Swedish addition to fmtcount, the word "åtta" is actually stored in a command taking an argument. Something like \newcommand*\@unitstring[1]{\ifcase#1 noll \or {\aa}tta \fi}. And I use \eappto to append that command.
    – Fredrik P
    Feb 12, 2023 at 22:22
  • @FredrikP That's too cryptic, sorry.
    – egreg
    Feb 12, 2023 at 22:31
  • New attempt before going to bed :-) tex.stackexchange.com/questions/675060/cannot-use-aa-in-eappto
    – Fredrik P
    Feb 12, 2023 at 22:38

You must log in to answer this question.

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