TransWikia.com

Change the font within chemacros iupac environment in with fontspec in lualatex?

TeX - LaTeX Asked on May 16, 2021

I asked this question not long ago, and now want to move from cfr-lm and pdflatex to newcomputermodern with fontenc and LuaLaTeX.

That is, I would like to use old-style numbers, everywhere except inside chemmacros iupac{} environment.

I’m not sure how to adapt the code from the previous answer but I’m not sure how to move from plstyle which continues on from the current position, to liningnums{} which covers only the text inside the brackets. Alternatively I’m sure fontspec has some way of manually adjusting those font features until the end of the environment, but I’m not sure how to do that without changing the whole document’s font. (chemformula has a built in command for this, but chemmacros does not.)

documentclass{article}
usepackage{fontspec}
defaultfontfeatures+{Numbers=OldStyle}
usepackage{newcomputermodern}
usepackage{chemmacros}

begin{document}
iupac{(1textit{R},2textit{R})-trans-1,2-Cyclohexanedicarboxylate} Old style

iupac{liningnums{(1textit{R},2textit{R})-trans-1,2-Cyclohexanedicarboxylate}} Lining

iupac{2,2':6',2''-terpyridine} Old style

iupac{liningnums{2,2':6',2''-terpyridine}} Lining

1234567890

liningnums{1234567890}

end{document}

One Answer

You can reuse the other answer. To switch to a different number style locally, use either addfontfeature, or define a new font family which has the right Number setting. I also suggest to restrict the defaultfontfeatures command to avoid that you get lots of warnings from the math font.

documentclass{article}
usepackage{fontspec}
defaultfontfeatures+[rmfamily,sffamily,ttfamily]{Numbers=OldStyle}
usepackage{newcomputermodern}

newfontfamilyncmliningnums{NewCM10-Book.otf}[
  Numbers=Lining,
  ItalicFont=NewCM10-BookItalic.otf,%
  BoldFont=NewCM10-Bold.otf,%
  BoldItalicFont=NewCM10-BoldItalic.otf,%
  SlantedFont=NewCM10-Book.otf,%
  SlantedFeatures={FakeSlant=0.25},
  BoldSlantedFont=NewCM10-Bold.otf,%
  BoldSlantedFeatures={FakeSlant=0.25}]


begin{document}

1234567890

{addfontfeatures{Numbers=Lining}1234567890}

{ncmliningnums 1234567890}

end{document}

enter image description here

Correct answer by Ulrike Fischer on May 16, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP