20

I'm typesetting a large amount of Latin texts using XeLaTeX and the package polyglossia. I'd like to get the small letter "u" automatically printed as "V" when turned into a capital letter (including small caps). Thus,

\documentclass{book}
\usepackage{fontspec,xltxtra,xunicode}
\usepackage{polyglossia}
\setmainlanguage{latin}
\begin{document}
Lorem ipsum\par
\textsc{Lorem ipsum}\par
LOREM IPSUM\par
\end{document}

should be printed with "u" – then "V" as small capital – the "V", capital letter.

  • 1
    What's wrong with sed and so forth? – jon Sep 1 '13 at 18:17
  • 3
    @Jon - I don't want to speak for the OP, but sed and friends might not be the right tool since they'll probably also operate on u and U characters contained in command names, such as \usepackage and \MakeUppercase... – Mico Sep 1 '13 at 18:53
  • Which font are you using? Would use of LuaLaTeX instead of XeLaTeX be an option? (Fortunately, polyglossia has recently become quite compatible with LuaLaTeX...) – Mico Sep 1 '13 at 18:55
  • @Mico -- I was thinking that if a 'large number of texts' are being typeset, it would be good to separate the contents and shell/preamble anyway; then simple regex tools would be appropriate. Although I'm not sure how best to deal with a 'u' buried in a \textsc{...u...} construction. – jon Sep 1 '13 at 19:00
21

If using LuaLaTeX rather than XeLaTeX is an option for you -- fortunately, Lua(La)TeX and polyglossia have started playing nice with each other, beginning a few months ago -- you may achieve your goal as follows. First, define an "OpenType feature file", such as

# Scripts and languages 
# If the font uses others, they should be defined here too
languagesystem DFLT dflt;
languagesystem latn dflt;

# Create two u to v substitutions and assign them to
# "required" ligature group
feature rlig {
  sub u.sc by v.sc;
  sub U by V;
} rlig;

Call this file, say, u-to-v.fea. Note that the substitution of various us to vs is assigned to the group of so-called "required" Ligatures. I suggest you do this because most Opentype font families I'm familiar with don't have "required" ligatures. That way, whatever you do with "required" ligatures is not going to interfere with the other work \fontspec performs. The following output

enter image description here

is produced by the following MWE:

% !TEX TS-program = lualatex
\documentclass{article}
\usepackage{fontspec}
\usepackage{polyglossia}
\setmainlanguage{latin}
\setmainfont[FeatureFile= u-to-v.fea, % file that contains the substitution rules
             Ligatures={Required}]    % enable "required" ligatures
            {EB Garamond}             % choose whatever Opentype font works for you
\newcommand{\spqr}{Senatus Populusque Romanus}
\begin{document}
\spqr                  % lowercase, no substitution needed

\textsc{\spqr}         % small caps, substitution is needed

\MakeUppercase{\spqr}  % uppercase, substitution is needed
\end{document}

Addendum, prompted by a follow-up comment by the OP: You ask how the scope of the u-to-v transformation may be limited to the latin parts of the document. One way to do this is to use \setmainfont to set up the document's general text font and the \newfontfamily command to set up another font with specific attributes (such as performing the u-to-v transformations). The example below provides some specific suggestions as to how this may be done.

Separately, it looks like you're going to be typesetting a lot of Latin text in all-smallcaps and/or all-uppercase letters, right? You may already know that most font families require some serious letterspacing to keep all-smallcaps and/or all-uppercase text from looking rather cramped. (I'd say the cramped look certainly results if EB Garamond, the text font used in the example above, is employed.) However, instead of fiddling with the letterspacing settings of a package such as microtype, you could use a font such as Trajan Pro that's already perfectly letterspaced for "petite caps" and regular uppercaps text. (Trajan Pro happens to be a system font on MacOSX; it may not be available free on other platforms.) Note that since Trajan Pro doesn't provide "offficial" small-caps, just lowercase letters that look like somewhat reduced-sized versions of the regular uppercase letters, a second Opentype feature file is required in the example below, to provide a substitution rule for u to v rather than for u.sc to v.sc. At any rate, o give some thought to the issue of which font, or which letterspacing settings, you should use to render the Latin portions of your document in a visually appealing way.

enter image description here

%% Feature File u2v-1.fea
languagesystem DFLT dflt;
languagesystem latn dflt;
feature rlig {
  sub u.sc by v.sc;
  sub U by V;
} rlig;



%% Feature File u2v-2.fea
languagesystem DFLT dflt;
languagesystem latn dflt;
feature rlig {
  sub u by v;
  sub U by V;
} rlig;



% !TEX TS-program = lualatex    
\documentclass{article}
\usepackage{fontspec}

\setmainfont[Ligatures={TeX,Common}]{EB Garamond}

\newfontfamily{\latinone}[FeatureFile = u2v-1.fea,
    Ligatures={NoCommon,Required}]{EB Garamond}

\newfontfamily{\latintwo}[FeatureFile = u2v-2.fea,
    Ligatures={NoCommon,Required}]{Trajan Pro}

% some LaTeX macros to encase text in latinone-lowercase, latinone-uppercase, etc
\newcommand{\latinonelc}[1]{{\latinone \scshape\MakeLowercase{#1}}}
\newcommand{\latinoneuc}[1]{{\latinone \MakeUppercase{#1}}}
\newcommand{\latintwolc}[1]{{\latintwo \MakeLowercase{#1}}}
\newcommand{\latintwouc}[1]{{\latintwo \MakeUppercase{#1}}}

\usepackage{polyglossia}
\setmainlanguage{latin}
\newcommand{\spqr}{Senatus Populusque Romanus}
\begin{document} 

\begin{tabular}{lll}
\spqr              & EB Garamond & unmodified\\[1ex]
\latinonelc{\spqr} & EB Garamond &  u.sc$\to$v.sc, all-smallcaps\\
\latinoneuc{\spqr} & EB Garamond & U$\to$V, all-uppercase\\[1ex]
\latintwolc{\spqr} & Trajan Pro  & u$\to$v, ``all-lowercase''\\
\latintwouc{\spqr} & Trajan Pro  & U$\to$V, all-uppercase
\end{tabular}
\end{document}
  • 2
    Nice solution. I'm not sure whether sub u by v; is wanted or not, probably not. – karlkoeller Sep 1 '13 at 19:47
  • 2
    Latin had only one letter for "u" and "v" (which was pronounced according to the context); in uppercase format it was "V" (ancient Latin had only what is now called uppercase); in the Middle Ages, lowercase started to be used and the letter was written in a form that became our "u". Much later the new letters "U" and "v" were adopted, together with "J" and "j"; see en.wikipedia.org/wiki/Latin_alphabet – egreg Sep 1 '13 at 20:36
  • 2
    This solution seems very nice, although I never used LuaLaTeX until now. I'll look into it. Would there be a way to assign the substitution to Latin only, in case of plurilingual files ? Thanks egreg for the historical precisions I neglected to give: that's indeed why, in Latin editions, we currently use only "u" as small letter and "V" as capital: uirgo - Virgilius - VIRGILIVS – Pierre Chambert-Protat Sep 2 '13 at 7:02
  • 1
    Your (new) images do not show the substitution..? Are you sure you don't mean to use filecontents*? – jon Sep 2 '13 at 20:02
  • 2
    EB Garamond is a bit funny as an example in this case. Try to use it with \addfontfeature{Language=Latin} ;). Capspacing is indeed a serious problem but at the moment I have to concentrate on other things. – georgd Sep 2 '13 at 20:46
4
\usepackage{xesearch}

\begin{document}

\MakeBoundary{abcdefghijklmnopqrstvwxyzABCDEFGHIJKLMNOPQRSTVWXYZ}
\SearchList*{lowercase}{v}{u}
\SearchList*{uppercase}{V}{U}

Lorem ipsum

Or hack with \catcode, make u to \active character class etc.

  • This doesn't work if I write a line with uU. – karlkoeller Sep 1 '13 at 19:31
  • True, for uU (and so on) one needs more SearchList*s. But in real life latin there should not be something like uUuUu to take care for. – Jori Mäntysalo Sep 1 '13 at 19:35
  • 1
    If my comment to Mico's answer is the wanted behavior, is there a way to have the substitution u->v only for smallcaps? – karlkoeller Sep 1 '13 at 20:28
  • In real Latin, however, you can easily get 'uu': uulgus, uulnus, uultus, and so on. – jon Sep 1 '13 at 20:33
  • For only smallcaps it should be simply matter of redefining \textsc. – Jori Mäntysalo Sep 2 '13 at 4:11

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.