Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Asterisk (*) in listings environment becomes lower #324

Closed
stone-zeng opened this issue May 6, 2018 · 4 comments
Closed

Asterisk (*) in listings environment becomes lower #324

stone-zeng opened this issue May 6, 2018 · 4 comments

Comments

@stone-zeng
Copy link

Consider the following code:

\documentclass{article}
\usepackage{listings,fontspec}

\newfontfamily\CodeFont{Source Code Pro}
\setmonofont{Source Code Pro}

\begin{document}

{CodeFont: \CodeFont emph*}

{ttfamily: \ttfamily emph*}

\begin{lstlisting}[basicstyle=\CodeFont]
\CodeFont:
\emph*{hello}
\end{lstlisting}

\begin{lstlisting}[basicstyle=\ttfamily]
\ttfamily:
\emph*{hello}
\end{lstlisting}

\end{document}

The result is

image

Notice that the asterisk is lower when using \CodeFont, but it's normal for \ttfamily.

I have tried other fonts. This issue appears when using Fira Code, Libertinus Mono etc, but doesn't show for CMU Typewriter.

Another test for Lucida Sans Unicode, however, shows that the asterisk (U+002A) becomes math asterisk (U+2217) improperly:

image

@qinglee
Copy link
Contributor

qinglee commented May 6, 2018

AFAIK this issue has nothing to do with fontspec. It is the black magic of the listings package.

We can see the following code fragment in listings.sty:

\lst@CCPutMacro
    ...
    \lst@ProcessOther {"2A}{\lst@ttfamily*\textasteriskcentered}
    ...
    \@empty\z@\@empty
\def\lst@ttfamily#1#2{\ifx\f@family\ttdefault#1\relax\else#2\fi}

The definition of \textasteriskcentered is located in the file tuenc.def:

\DeclareTextCommand{\textasteriskcentered}\UnicodeEncodingName{%
  \iffontchar\font"2217 \char"2217 \else
    \begingroup
      \fontsize
       {\the\dimexpr1.2\dimexpr\f@size pt\relax}%
       {\f@baselineskip}%
      \selectfont
      \raisebox{-0.6ex}[\dimexpr\height-0.6ex][0pt]{*}%
    \endgroup
  \fi
}

@stone-zeng
Copy link
Author

Everything goes OK after loading the xunicode package. I guess that this problem appears because fontspec and ctex all become independent of xunicode recently.

@qinglee
Copy link
Contributor

qinglee commented May 6, 2018

\textasteriskcentered is exactly the same as * (U+002A) in xunicode:

\DeclareUTFcharacter[\UTFencname]{x002A}{\textasteriskcentered}

@wspr
Copy link
Collaborator

wspr commented Jul 31, 2018

Interesting discussion but I agree this isn't a fontspec issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants