latex3 / fontspec

Font selection in LaTeX for XeTeX and LuaTeX
http://latex3.github.io/fontspec/
LaTeX Project Public License v1.3c
276 stars 33 forks source link

doc: \ttdefault and friends can't be modified #386

Closed lemzwerg closed 4 years ago

lemzwerg commented 4 years ago

As discussed in https://tex.stackexchange.com/questions/512432/xelatex-libertine-renewcommand-ttdefault-no-longer-works/512548, please document that manipulation of \ttdefault and siblings has no influence since fontspec version 2.6.

\documentclass{article}

\usepackage{fontspec}
\setmonofont{Fira Mono}
\renewcommand\ttdefault{lmtt}

\begin{document}
foo \texttt{bar}
\end{document}
RuixiZhang42 commented 4 years ago

Here are my two cents on this issue: I will use \setmonofont as an example. The commands \setmainfont and \setsansfont should be considered too.

https://github.com/wspr/fontspec/blob/c1fdf6d52c75017656c4d99ca5b4711353da125d/fontspec-code-user.dtx#L86-L103

As a reference, here is the definition of \ttfamily in the LaTeX2e kernel: https://github.com/latex3/latex2e/blob/c32747acdc17a30e55e374e4926bfa9680875b1d/base/ltfssini.dtx#L168-L170

wspr commented 4 years ago

Thanks both. This is almost certainly an oversight since I have:

\tl_set_eq:NN \ttdefault \l_@@_ttfamily_family_tl

first, it only makes sense to keep using \ttdefault here:

        \exp_not:N \fontfamily { \l_@@_ttfamily_family_tl }

I’ll try to fix up and run some tests, but I’m afraid I’m pretty snowed under at work at the moment.

If you’d like to write some short fontspec test files for the repository I could probably patch immediately…

I’m actually quite confused why I have this code written in this way. There must have been some reason (I assume!!) that I didn’t just write something more like:

    \DeclareRobustCommand \ttfamily
      {
        \fontencoding { \g_@@_nfss_enc_tl }
        \fontfamily { \l_@@_ttfamily_family_tl }
        \selectfont
      }

Or maybe there was once a reason and it’s no longer applicable...

RuixiZhang42 commented 4 years ago

@wspr I never worked with the LaTeX3 validation system before. But guessing from the existing files, does the test file you seek look like this?

\input{fontspec-testsetup.tex}
\usepackage{fontspec}
\begin{document}

\TIMO\SEPARATOR
\MSG{SET FONT FAMILIES}
\setmainfont{texgyretermes-regular.otf}
\setsansfont{texgyreheros-regular.otf}
\setmonofont{texgyrecursor-regular.otf}

\rmfamily
\CURRNFSS

\sffamily
\CURRNFSS

\ttfamily
\CURRNFSS

\TIMO\SEPARATOR
\MSG{REDEFINE FONT FAMILIES}
\renewcommand\rmdefault{lmr}
\renewcommand\sfdefault{lmss}
\renewcommand\ttdefault{lmtt}

\rmfamily
\CURRNFSS

\sffamily
\CURRNFSS

\ttfamily
\CURRNFSS

\end{document}
wspr commented 4 years ago

@RuixiZhang42 — many thanks!!

schlcht commented 4 years ago

I'm not quite sure whether I like the current solution of patching \rmfamily and friends unconditionally (and not only if the corresponding fontspec command has been issued) (commits 06471c9 and 127ad61). This makes it quite hard to mix Unicode and legacy fonts in a document. Consider for example this:

\documentclass{article}
\usepackage{fontspec}
\usepackage[T1]{fontenc}
\def\rmdefault{qtm}
\rmfamily
\stop

which fails to load T1/qtm, because latex is trying to find TU/qtm instead. (The same BTW for the MWE from the OP, if you replace lmtt with any other font that doesn't have a TU definition.)

wspr commented 4 years ago

@schlcht — you're right, I forgot to test this use case. Fixing this up now, thanks very much.

wspr commented 4 years ago

@schlcht — now fixed I hope.

schlcht commented 4 years ago

@wspr Yes, thanks a lot for the quick response!