# How to use previously downloaded fonts with lualatex engine and python to create pdf file

How and where to install .ttf fonts which I've already downloaded from web. I've created latex file using online overleaf. Inside same directory I put all my .ttf fonts and LuaLaTeX engine and everything works fine.

But, I have problem when I am using python to render same latex template. This is cmd which define where lualatex is installed on Ubuntu server, where to place latex file and third where latex template is situated. The aim of this is to create pdf from latex template.

cmd = "/usr/bin/lualatex -output-directory=/home/somepath/app/static/users_documents/" + str(
user_id) + " /home/somepath/" + tex_file
ps = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
output, err = ps.communicate()
print(output, err, ps.returncode)


This is part of latex document where I define fonts

\documentclass[a4paper,10]{article}
\usepackage[zw32010,crossmark]{ticket}
\usepackage{graphicx}

\usepackage{fontspec}
\setsansfont{[Segoe_UI_Bold.ttf]}

\newfontfamily{\segoeui}{segoeui}[
Extension=.ttf
]

\newfontfamily{\centuryItalic}{Century_Gothic_Italic}[
Extension=.ttf
]

\newfontfamily{\segoeuiItalic}{Segoe_UI_Italic}[
Extension=.ttf
]

\newfontfamily{\segoeuibold}{Segoe_UI_Bold}[
Extension=.ttf
]


So, the question is how to enable lualatex from Ubuntu directory:

/usr/bin/lualtex


to see and use .ttf fonts?

I have to mention that I have only access to Ubuntu (16.04.3) command line.

This is part of the error:

luaotfload | load : unsupported font option: nil
bad argument #1 to 'gsub' (string expected, got nil).
\scan_stop:
l.7 \setsansfont
{[Segoe_UI_Bold.ttf]}
?
! Emergency stop.

• I've used overleaf answer from frequently questions overleaf.com/learn/latex/Questions/… and as I can see we can use font in this form \setmainfont{[CrimsonText-Regular.ttf]} or \setmainfont{CrimsonText}[ Extension = .ttf, UprightFont = *-Regular, ...] Nov 7, 2018 at 9:49
• You could use the cwd= option for Popen(). Set it to the directory with your document and fonts. Nov 7, 2018 at 13:33
• Thanks Sergei, but I've already resolved problem using Path in latex. Nov 7, 2018 at 15:26

You should load the fonts like this:

\documentclass[a4paper,10]{article}

\usepackage{fontspec}
\setsansfont{Segoe_UI_Bold}[
Extension   = .ttf,
Path        = /path/to/fonts/
]

\newfontfamily{\segoeui}{segoeui}[
Extension   = .ttf,
Path        = /path/to/fonts/
]

\begin{document}

Something

\end{document}