4

There is plain \uppercase macro as well as \MakeUppercase in latex3. The last one works perfectly fine with two bits utf-8 characters as long as you explicitly brace the argument

\MakeUppercase{здравей}

Now I would like to capitalize the only the first letter of a word. Of course you can make it straight \MakeUppercase{з}дравей and it will work, however in the real use-case, the word is variable and stored in a macro:

\def\footext{здравей}
\expandafter\MakeUppercase\footext

And here the problem rise up that David Carlisle greatly explained under this post: latex3 — issues with cyrillic.

Basically, because of that no command could grab first letter if not specified the argument explicitly:

\def\foo#1{#1}
\foo здарвей % error, the argument is only the first bit of 'з'

Is there a clever yet simple way of getting the desired result despite the text? So that it should support both one bit and two bit characters (even mixed).


Meanwhile I tried to create a bulk workaround, based on Ulrike Fischer's solution of unprotecting utf-8 character.

\documentclass{article}
\usepackage[T2A]{fontenc}

\makeatletter \def\expandutfvii{% \count@"C2 @tempcnta"F5 \def\UTFviii@tmp{\expandafter\def\expandafter~\expandafter{~}}% \UTFviii@loop } \makeatother

\begin{document}

\ExplSyntaxOn \expandutfvii \tl_set:Nn \l_tmpa_tl {здравей} \exp_last_unbraced:Nx \str_uppercase:n \l_tmpa_tl \ExplSyntaxOff

\end{document}

It almost works, but I couldn't evaluate the string so that it would use those commands instead of printing them enter image description here

antshar
  • 4,238
  • 9
  • 30

2 Answers2

7

Use \MakeTitlecase (this requires a current LaTeX, the underlying expl3 command \text_titlecase:n can be used also in older systems).

\documentclass{article}
\usepackage[T2A]{fontenc}

\begin{document}

\MakeUppercase{з}дравей

\MakeTitlecase{здравей}

\end{document}

enter image description here

Ulrike Fischer
  • 327,261
2

Your problem is that you are using old 8bit TeX engine, no Unicoded engine in 2022. We have Unicode standard more than 20 years now an there is plenty fonts supporting it.

For example, when we use OpTeX (which is based on LuaTeX engine, supports Unicode) then there is no problem:

\fontfam[newcm]
\def\uppercasefirst#1{\uppercase{#1}}

\uppercasefirst здравей.

\bye

wipet
  • 74,238
  • While it's easier in luatex, The problem was not that the user was using pdftex, rather that he was using an old latex without suitable support. Also as typical with latex, \MakeTitlecase does more than simple plain tex #1 as you show here: it is doing locale sensitive titlecasing (which might mean IJ not Ij in dutch or keeping an accent in Greek even when \MakeUppercase drops accents as that is the specified behavour for Greek. (actually specifying the locale currently requires expl3, but that will change) – David Carlisle Aug 08 '22 at 08:44