Fonts & Character SetsSetting Arial in fontspec has no effect on the resulting PDF compiled by xelatex

Information and discussion about fonts and character sets (e.g. how to use language specific characters)
Post Reply
thinkpadder
Posts: 11
Joined: Fri May 21, 2021 12:01 pm

Setting Arial in fontspec has no effect on the resulting PDF compiled by xelatex

Post by thinkpadder »

I write a tutorial about programming using Markdown and convert it into PDF with Pandoc. However, because the default (Tex) font doesn't look appropriate for the purposes of the tutorial and the default margins are too big for the PDF, I first convert the Markdown into the tex file:

pandoc.exe my-latex-doc.md -t latex -o my-latex-doc.tex --standalone

and edit the tex file to add these:

\usepackage[left=1.5cm, right=2cm, top=2cm]{geometry}
\usepackage{fontspec}\setmainfont[]{Arial}


and do xelatex.exe my-latex-doc.tex

The tex file is compiled without any errors.

The resulting PDF displays the changes made to the margins but it doesn't display the Arial font. Here is the resulting PDF:
my-sample-tex.png
my-sample-tex.png (27.06 KiB) Viewed 12592 times
I've tried compiling with the lualatex.exe, too but the result's the same i.e. it gets compiled fine but it doesn't display the Arial font. (I 've first tried using pdflatex, but it turned out that it wasn't capable of compiling fontspec)

The complete tex file in full:

Code: Select all

Code, edit and compile here:
% Options for packages loaded elsewhere
\PassOptionsToPackage{unicode}{hyperref}
\PassOptionsToPackage{hyphens}{url}
%
\documentclass[a4paper,12pt]{article}
% -------------------------------------------
\usepackage[left=1.5cm, right=2cm, top=2cm]{geometry}
% \usepackage[T1]{fontenc}
% \usepackage{charter}
\usepackage{fontspec}\setmainfont[]{Arial}
% \setmainfont{texgyretermes-regular.otf}[
% BoldFont=texgyretermes-bold.otf,
% ItalicFont=texgyretermes-italic.otf]
% --------------------------------------------
\usepackage{amsmath,amssymb}
\usepackage{lmodern}
\usepackage{iftex}
\ifPDFTeX
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{textcomp} % provide euro and other symbols
\else % if luatex or xetex
\usepackage{unicode-math}
\defaultfontfeatures{Scale=MatchLowercase}
\defaultfontfeatures[\rmfamily]{Ligatures=TeX,Scale=1}
\fi
% Use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
\IfFileExists{microtype.sty}{% use microtype if available
\usepackage[]{microtype}
\UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
}{}
\makeatletter
\@ifundefined{KOMAClassName}{% if non-KOMA class
\IfFileExists{parskip.sty}{%
\usepackage{parskip}
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
I'm using MikTeX-21.2 (the latest version) and the Pandoc-2.13 on Windows 7.

How to edit the tex file or any other thing so that the PDF displays the desired font, Arial or any other font?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Ijon Tichy
Posts: 640
Joined: Mon Dec 24, 2018 10:12 am

Setting Arial in fontspec has no effect on the resulting PDF compiled by xelatex

Post by Ijon Tichy »

As long as you load other font package like lmodern setting of the main font with \setmainfont before loading the font package doesn't work, because loading of the font package will also change the main font. BTW: You should not load legacy font package like lmodern if you work with XeLaTeX or LuaLaTeX.
Last edited by Ijon Tichy on Fri May 21, 2021 4:37 pm, edited 1 time in total.
Sorry, but I can no longer participate here as the administrator is trampling on my wishes on one of his other platforms. :cry:
thinkpadder
Posts: 11
Joined: Fri May 21, 2021 12:01 pm

Setting Arial in fontspec has no effect on the resulting PDF compiled by xelatex

Post by thinkpadder »

Ijon Tichy wrote:As long as you load other font package like lmodern setting of the main font with \setmainfont before loading the font package doesn't work, because loading of the font package will also change the main font. BTW: You should not load legacy font package like lmodern if you work with XeLaTeX or LuaLaTeX.

BTW: Your example code is not complete. Loading of the class is missing.
Thank you for the answer. It worked out. I've carried the \usepackage{fontspec}\setmainfont[]{Arial} line to the line right before the \begin{document} and recompiled with xelatex and finally the Arial font showed up.

Actually, all those codes including lmodern are produced by the Pandoc. The only codes I've added were those at the start between those 2 % ----------------------- lines; I had tried them by commenting in and out. Because I thought adding fontspec anywhere in the document would definitely change the default font, so I've added it into between those 2 comment lines. In this context, I didn't even notice that lmodern lines were there, because they were added by Pandoc.
Post Reply