2

I have some letters with macron above (in fact I have only ū and ā), they work pretty. But in small caps, when I set \setmainfont{CMU Serif} it totally fail. Instead of small cap letter, I get small letter with macron above.

Then, with the following MWE:

\documentclass{standalone}
\usepackage{fontspec}

\setmainfont{CMU Serif}

\begin{document}
āū

ĀŪ

\textsc{AāūU}
\end{document}

I get this rendering

It’s annoying because without \setmainfont{CMU Serif} it work pretty well. But I can’t remove thi font because it fix a lot of other problems, it only cause this one.

So, now their is too solution:

The quick solution

Just fix the two needed chars with \newunicodechar{}

The long solution

Tell xelatex to just use the default font for chars with macron.

To be honest, the quick solution will be widely satisfying.

1

Although that font doesn’t have a smcp mapping for precomposed characters with the macron, you can instead tell it to use the combining macron accent, U+0304. That enables the quick solution.

\documentclass{standalone}
\usepackage{fontspec}
\usepackage{newunicodechar}

\newunicodechar{ā}{\accent"0304 a}
\newunicodechar{ū}{\accent"0304 u}

\setmainfont{CMU Serif}

\begin{document}
āū

ĀŪ

\textsc{AāūU}
\end{document}

CMU Serif font sample

You might want the macron over the small capital A shifted to the right. You can do this with \skew.

  • I don’t know why but this solution cause a lot of troubles with I compile it. See by yourself (framapic.org/TKs4Ok1cbsTP/UTqHER9kXEC1). – fauve Jul 27 '19 at 14:26
  • @fauve You might be running an older version of the package or fonts. See @egreg’s solution for something more robust, or replacing "0304 with "00AF might work for you. – Davislor Jul 27 '19 at 18:07
1

You can test whether +smcp is present in the current font identifier; if it is, use the \accent primitive with U+00AF MACRON over the simple letter, otherwise use the composite.

\documentclass{article}
\usepackage{fontspec}
\usepackage{newunicodechar}

\setmainfont{CMU Serif}

\newunicodechar{ā}{\checksc{a}{ā}}
\newunicodechar{ū}{\checksc{u}{ū}}

\ExplSyntaxOn
\NewDocumentCommand{\checksc}{mm}
 {
  \str_if_in:enTF {\fontname\font}{+smcp}
   { \accent"00AF\scan_stop: #1 }
   { #2 }
 }
\prg_generate_conditional_variant:Nnn \str_if_in:nn { e } { T,F,TF }
\ExplSyntaxOff

\begin{document}

āū

ĀŪ

\textsc{AāūU}

\end{document}

enter image description here

The instances of ā and ū in normal fonts will copy-paste correctly from the PDF; not those in small caps (I don't think you can do much about it).

A possible improvement for lowering the accent; act on \kern-0.1ex to modify the distance.

\documentclass{article}
\usepackage{fontspec}
\usepackage{newunicodechar}

\setmainfont{CMU Serif}

\newunicodechar{ā}{\checksc{a}{ā}}
\newunicodechar{ū}{\checksc{u}{ū}}

\ExplSyntaxOn
\NewDocumentCommand{\checksc}{mm}
 {
  \str_if_in:enTF {\fontname\font}{+smcp}
   { \fauve_emulate_accent:nn { "00AF } { #1 } }
   { #2 }
 }
\prg_generate_conditional_variant:Nnn \str_if_in:nn { e } { T,F,TF }
\cs_new_protected:Nn \fauve_emulate_accent:nn
 {
  \vbox{\offinterlineskip\halign{\hfil##\hfil\cr\symbol{#1}\cr\noalign{\kern-0.1ex}\smash{#2}\cr}}
 }
\ExplSyntaxOff

\begin{document}

āū

ĀŪ

\textsc{AāūU}

\end{document}

enter image description here

0

I find the best solution with \stackinset from stackengine package. I had to redifine ā with \stackinset{c}{}{t}{-0.1em}{¯}{a} As you can see the inset item should be the unicode char ¨ because when I used the TeX command \={} (to make macron) the result failed.

\documentclass{article}
\usepackage{fontspec}
\usepackage{stackengine}
\usepackage{newunicodechar}



\makeatletter
\newunicodechar{ā}{\stackinset{c}{}{t}{-0.1em}{¯}{a}}
\newunicodechar{ū}{\stackinset{c}{}{t}{-0.1em}{¯}{u}}
\makeatother

\setmainfont{CMU Serif}


\begin{document}
ā

āū

\emph{āū}
\textbf{āū}

ĀŪ

\textsc{AāūU}

\textsc{aāūu}

\end{document}

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.