3

Basically, I want to achieve the same as for instance in this question: Changing the math-mode figures to “old style”. But not in general math, only for URLs, which are set in math mode (in the manual, I read that this is done due to “context-sensitive linebreaking”).

So, a simple MWE:

%!TEX program=lualatex
\documentclass{article}
\usepackage[no-math]{fontspec}
\usepackage{unicode-math}
\usepackage{url}
\urlstyle{same}

\setmainfont[Numbers={OldStyle}]{Libertinus Serif} \setmathfont[]{Libertinus Math}

\begin{document}

math: $123$

text: 123

url: \url{123}

\end{document}

enter image description here

The math number should of course stay as they are, but I would prefer to have the same number style in URLs as in normal text. In the MWE, I used the predefined url-style \urlstyle{same}. For custom styles, I would use the macro \renewcommand*{\UrlFont}{\mathversion{osf}\normalfont} and define a suitable math version with \setmathfont[version=osf,....enable oldstyle numbers....]{Libertinus Math}. However, I do not know how to “activate” old-style numbers with unicode-math. When adding the option Numbers={OldStyle} as for the the main font, I do not observe any effect.

Edit

I tried it with \mathversions and substitituting only a range, but this does not work. But \mathversions alone work – at least for equations put inside $ signs. For URLs, it is somehow ignored.

Update MWE

%!TEX program=lualatex
\documentclass{article}
\usepackage[no-math]{fontspec}
\usepackage{unicode-math}
\usepackage{url}
\renewcommand*{\UrlFont}{\mathversion{osf}}

\setmainfont[Numbers={OldStyle}]{Libertinus Serif} \setmathfont{Libertinus Math}[version=default] \setmathfont{Libertinus Serif}[version=osf,Numbers=OldStyle]

\begin{document}

\mathversion{osf}
math (osf): $123$

\mathversion{default}
math (default): $123$

text: 123

url: \url{123}

\end{document}

enter image description here

crateane
  • 2,217
  • You’d declare the old-style numerals in math mode with \setmathfont{Libertinus Serif}[range=up/digits, Numbers=OldStyle] and the math version with version=osf. Unfortunately, range= and version= are mutually exclusive as of 2021. – Davislor May 09 '21 at 14:29
  • A solution might be to \setmathrm and use the \mathrm font in math mode, but the way \url is defined seems to be set up to use commands such as \rmfamily or \ttfamily, not \mathrm{123}. – Davislor May 09 '21 at 14:30
  • @Davislor I found out the same thing (the incompability of ranges/versions), see my edit :/ your second comment probably explains the remaining effect of url not showing OSFs. – crateane May 09 '21 at 14:32
  • The URL implementation of hyperref might work better for you? – Davislor May 09 '21 at 14:33
  • @Davislor Oh, I thought, hyperref uses the url package? I do use hyperref indeed, and wanted to change the appearance of links. – crateane May 09 '21 at 14:35

1 Answers1

5

url uses math mode, but the font is the text font. I'm using tex gyre heros below to make the difference more obvious.

The problem is that math mode in lualatex requires fonts that use the basic renderer, but text fonts typically want the node or harf mode. You can try to force the basic mode for the url's, but it can mean that you loose text options which work only with node mode. A real solution would require a reimplementation of url which doesn't use math mode.

\documentclass{article}
\usepackage[no-math]{fontspec}
\usepackage{unicode-math}
\usepackage{url}
\def\UrlFont{\addfontfeature{Renderer=Basic}}

\setmainfont[Numbers={OldStyle}]{TeX Gyre Heros} \setmathfont[]{Libertinus Math}

\begin{document}

math: $123$

text: 123

url: \url{123}

\end{document}

enter image description here

Ulrike Fischer
  • 327,261
  • Thank you, this seems to do exactly what I looked for! Are there any noticable effects of 'loosing text options'? (worst case maybe loosing some characters?) – crateane May 09 '21 at 14:45
  • 1
    no you won't loose chars, but some open type features won't work, like e.g. stylistic sets. see a longish discussion here https://github.com/lualatex/luaotfload/issues/204 – Ulrike Fischer May 09 '21 at 14:49
  • 1
    OK, thanks, I think I can live with this for now (URLs in the reference list). – crateane May 09 '21 at 14:59