TransWikia.com

Multiple fonts in a numbered section heading with XeLaTeX and Hyperref

TeX - LaTeX Asked by Kettamon on May 25, 2021

I’m trying to use XeLaTeX to build my document. I define sections containing two different fonts within the section command. I’ve managed to get this to work, but only when using the * version to remove numerals. If hyperref is included, then the regular version of the command fails.

documentclass{article}
usepackage{fontspec}
usepackage{titlesec}
usepackage{hyperref}

newfontfamilyfontTNR{Times New Roman}
newfontfamilyfontAN{Arial}

DeclareTextFontCommand{fontA}{fontTNRfontsize{16}{19.2}selectfont}
DeclareTextFontCommand{fontB}{fontANfontsize{16}{19.2}selectfont}

begin{document}

section*{fontA{Text1} fontB{Text2}}

end{document}

This passes through just fine. However, the following version with the * removed fails due to conflicts with hyperref.

documentclass{article}
usepackage{fontspec}
usepackage{titlesec}
usepackage{hyperref}

newfontfamilyfontTNR{Times New Roman}
newfontfamilyfontAN{Arial}

DeclareTextFontCommand{fontA}{fontTNRfontsize{16}{19.2}selectfont}
DeclareTextFontCommand{fontB}{fontANfontsize{16}{19.2}selectfont}

begin{document}

section{fontA{Text1} fontB{Text2}}

end{document}

I’ve tried looking into the hyperref file to trace the error but it is honestly far beyond my comprehension at this time. Here is the error I get from the log.

Example of the error list, captured from TeXStudio.

I’m assuming this has something to do with the way hyperref manages indices. Perhaps when section* is used this conflict is removed when the section is stripped from the table of contents?

I did look into using titlesec as a method of doing this task but failed to see how I could apply multiple fonts to the content with just a format specification.

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