4

Consider the following example:

\documentclass{article}
\usepackage{fontspec}
\usepackage{unicode-math}
\setmonofont{NewCMMono10-Regular} % any other typewriter font would do

\begin{document}

\setlength{\parfillskip}{0pt plus 10pt}

\texttt{some text with whitespaces}

\texttt{some-text-with-whitespaces}

\end{document}

The result with XeLaTeX would be:

enter image description here

This does not happen if one writes \setmonofont before loading unicode-math, or if the line \usepackage{unicode-math} is removed.

Since this does not happen with LuaLaTeX, I think it is not the expected behavior? Thus is there some way to fix this?

4
  • \fontdimen3 stretch component for space should normally be 0pt for monospace fonts but it's 2.625pt. after unicode-math, looking... Feb 25 at 11:23
  • Can you raise at unicode-math github (which is under latex3 these days) Feb 25 at 11:38
  • @DavidCarlisle Sure, I shall soon write an Issue. I was just asking it here to see if it is something that has been asked before.
    – Jinwen
    Feb 25 at 11:51
  • 1
    @DavidCarlisle it looks more like a fontspec problem. You get the same problem without unicode-math if you reuse the font name in a new (non tt) font family: \setmonofont{NewCMMono10-Regular} % \newfontfamily\blub{NewCMMono10-Regular}. Feb 25 at 16:24

2 Answers 2

4

It's not clear why the interword space gets flexibility. You can repair the misfeature, though.

\documentclass{article}
\usepackage{fontspec}
\usepackage{unicode-math}

\setmonofont{NewCMMono10-Regular}[
  WordSpace={1,0,0},
]

\begin{document}

\setlength{\parfillskip}{0pt plus 10pt}

\texttt{some text with whitespaces}

\texttt{some-text-with-whitespaces}

\end{document}

enter image description here

3
  • ah I thought there ought to be fontspec key somewhere, I guess I'll have to upvote this:-) Feb 25 at 16:08
  • @DavidCarlisle Too bad, isn't it?
    – egreg
    Feb 25 at 16:14
  • disaster....... Feb 25 at 16:19
3

The fontdimen parameters 3 and 4 setting the stretch and shrink for a space are being set non zero after unicode-math that looks like a bug, you can force them back to 0pt with eg

\documentclass{article}
\usepackage{fontspec}
\usepackage{unicode-math}


\setmonofont{NewCMMono10-Regular} % any other typewriter font would do
\AddToHook{cmd/ttfamily/after}{%
  \fontdimen3\font=0pt\relax
  \fontdimen4\font=0pt\relax}

\begin{document}

\setlength{\parfillskip}{0pt plus 10pt}

\texttt{some text with whitespaces\showthe\fontdimen3\font}

\texttt{some-text-with-whitespaces}

\end{document}

but that shouldn't be necessary

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .