1

I would like to use the fontspec package to change the font family.

I use four different fonts in the same document and want to create a font family based on the fonts installed on my Windows machine, using font switches and font functions to change the font.

Ingmar
  • 6,690
  • 5
  • 26
  • 47
Mohamed
  • 89
  • 6
  • 3
    Please tell us what you've tried so far, and please tell us more about the "four different fonts" you wish to use. E.g., are they text fonts, or is one or the other a math font? Please also indicate if you've looked at the user guide of the fontspec package and, if so, have come across the \setmainfont, \setsansfont, \setmonofont, and \newfontfamily commands. (Hint: to open the user guide in a pdf browser, open a command window and type texdoc fontspec.) – Mico Apr 16 '21 at 05:25
  • \documentclass[]{article} \usepackage{fontspec} \newfontfamily\Ofont{Oswald Regular} \newfontfamily\Rfont{Roboto} \newfontfamily\RLfont{Roboto Light} \newfontfamily\Afont{Algerian} \begin{document} \end{document} – Mohamed Apr 16 '21 at 05:34
  • i want to know how to use to change font for some text in middle of paragraph. is \Ofont a switch or function – Mohamed Apr 16 '21 at 05:36
  • 1
    \Ofont is a switch. – Cicada Apr 16 '21 at 05:45
  • To make a function (command), you can do \newcommand{\myofont}[1]{{\Ofont #1}} and then do \myofont{Some text printed in Oswald Regular}. Note the extra brackets to restrict the font switch to within a group. – Cicada Apr 16 '21 at 05:48

1 Answers1

5

Very basic example. fontspec is very powerful.

example

MWE

\documentclass{article}
\usepackage{xcolor}
\usepackage{fontspec}
\setmainfont{Noto Serif}
\setsansfont{Noto Sans}
\setmonofont{Noto Sans Mono}
\newfontfamily{\fcyc}{cyklop}
\newfontfamily{\falg}{AlgolRevived}[Scale=1.5,Color=red]
\newfontfamily{\fsong}{FandolSong}
\begin{document}
\Large
This is the default roman text for the document (the main font).

{\sffamily This is the sans font. 123456}

{\ttfamily This is the mono-spaced font: 123 456 789.}

Here is an example of a font-switch: \falg ABC abc 123 \normalfont and then switch back to normal font.

{\fcyc Abc cyklop font} -- this font is restricted to a group with { }.

Some random characters in FandolSong font: \fsong 一丢人伺\normalfont

Back to normal font again.

\end{document}

Cicada
  • 10,129
  • why \fcyc with a bracket and \sfong without a bracket???? – Mohamed Apr 16 '21 at 05:39
  • 2
    They are switches: the brackets {} restrict the font switch to inside the brackets only. Without brackets, the font switch is in effect until another font switch. Try an experiment. – Cicada Apr 16 '21 at 05:42