6

After fixing the issue Single quotes do not seem to be scaled with xelatex and Source Code Pro, I discovered that carets also failed to render with my recent LaTeX update. This is what they looked like in PDF before (about a month ago):

old

Now they look like this:

new

A minimal example (to be compiled via xelatex):

\documentclass[12pt]{article}
\usepackage{fontspec}

\begin{document}

two carets (\texttt{\^{}}) produce a superscript (e.g.,
\texttt{ClO\^{}-1\^{}} renders ClO\textsuperscript{-1})

\end{document}

I know I probably should use \textasciicircum{} instead of \^{}, but this is not under my control, since I'm using Pandoc to convert my Markdown source document to LaTeX, and ^ is translated to \^{}. FWIW, this works correctly but I wonder if I can make \^{} work:

two carets (\texttt{\textasciicircum{}}) produce a superscript (e.g.,
\texttt{ClO\textasciicircum{}-1\textasciicircum{}} renders ClO\textsuperscript{-1})
1
  • Imho you should ask pandoc to change its output. Even if you can use a lot of tricks to tweak the output on the latex side it is not a sane input to use an accent command to get a char. \textasciicircum or \string^ would be better. Feb 18, 2017 at 13:03

2 Answers 2

7

You can test if #1 is empty

\documentclass[12pt]{article}
\usepackage{fontspec}
\let\OldCircum\^
\def\^#1{%
  \ifx\relax#1\relax
    \textasciicircum
  \else
    \OldCircum#1%
  \fi
}
\begin{document}

two carets (\texttt{\^{}}) produce a superscript (e.g.,
\texttt{ClO\^{}-1\^{}} renders ClO\textsuperscript{-1})

\^o
\end{document}
5
  • 3
    yes I wonder if we should do that in the core... Feb 16, 2017 at 21:02
  • and the same for \textasciitilde
    – user2478
    Feb 17, 2017 at 12:27
  • yes the default TU accents use suffix combining characters and the helper function for that should probably guard against empty base in all cases. Feb 17, 2017 at 12:42
  • After I updated the latex package today, this solution is broken. The log file: pastebin.com/yLZfzCEq My original example also fails to compile now.
    – Yihui Xie
    Feb 22, 2017 at 22:47
  • Sorry please see tex.stackexchange.com/a/355239/1090 Feb 23, 2017 at 7:37
2

The issue applies to all accents in TU encoding. If no precomposed glyph is present then it falls back to using a combining character but if the base is empty this then combines with the previous character.

we should fix this in the base release but you can add a guard so that an empty base is detected and replaced by no-break space.

enter image description here

\documentclass[12pt]{article}
\usepackage{fontspec}

\makeatletter
\def\add@unicode@accent#1#2{%
  \if\relax\detokenize{#2}\relax\string^^a0\else#2\fi\char#1\relax}
\makeatother

\begin{document}

two carets (\texttt{\^{}}) produce a superscript (e.g.,
\texttt{ClO\^{}-1\^{}} renders ClO\textsuperscript{-1})

\end{document}
8
  • This works for my original example, but does not work if I use a custom font, e.g. add \setmonofont[Scale=0.7]{Source Code Pro} to the preamble. Output: i.imgur.com/Z9WDMNn.png
    – Yihui Xie
    Feb 18, 2017 at 3:28
  • 1
    @Yihui that's what makes unicode setting "interesting" unlike traditional tex where we had complete control, with opentype it's more like making a general request that the font does something, but ultimately it can do whatever it likes. Thanks for the example, I'll need to think about what to do in the default format settings Feb 18, 2017 at 9:35
  • @Yihui there is something very odd about the combining ^ in that font, see chat.stackexchange.com/transcript/message/35520593#35520593 Feb 18, 2017 at 10:18
  • Like Herbert's answer above, this solution is also broken after a latex update today. Log file at pastebin.com/yLZfzCEq It seems \DeclareTextComposite{\^} \UnicodeEncodingName {}{"005E} on line 252 of tuenc.def is problematic.
    – Yihui Xie
    Feb 23, 2017 at 4:22
  • 1
    @Yihui the fixed code is on ctan so will probably get to texlive tomorrow or the day after, sorry about the inconvenience. Feb 23, 2017 at 21:49

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.