1

File structure is:

fonts
     Roboto-Regular.ttf
main.tex

The document is essentially:

\documentclass{article}

\RequirePackage[utf8]{inputenc}
\RequirePackage{fontspec}

\newfontfamily [ Path = /fonts/,
 UprightFont = *-regular,
 BoldFont = *-bold, ...]
 {Roboto}

\title{TITLE}
\author{MY NAME}
\date{February 2018}

\begin{document}

\maketitle
\section{Introduction}

\end{document}

It then gives me Undefined control sequence, missing \begin{document}. I've tried so many things I can't figure out what I'm doing wrong.

EDIT I also tried:

    \setmainfont{Roboto}[
    Path = /fonts/,
    Extension = .ttf,
    UprightFont = *-Regular,
    BoldFont = *-Bold,
    ItalicFont = *-Italic,
    ...
]
  • You are missing the first mandatory argument to the \newfontfamily command. The first argument must be a control sequence, for example: \newfontfamily{\myfamily}[options]{FontName} – Phelype Oleinik Feb 16 '18 at 18:07
  • tried that but it's still giving me the same error when I add {\myfamily}, is that supposed to be a placeholder? – Alexis Drakopoulos Feb 16 '18 at 18:09
  • It should also be Path=./fonts/. Probably you want \setmainfont rather than \newfontfamily. – egreg Feb 16 '18 at 18:16
  • 2
    The same error? Probably not. With the same setup as you, I compiled with XeLaTeX and \setmainfont{Roboto}[Path=./fonts/,Extension = .ttf,UprightFont = *-Regular,BoldFont = *-Bold,ItalicFont = *-Italic] and it worked. Make sure you are adding the dot before the path and that you remove the .... Also check if the folder name has some capital letter. Off-topic: remove the inputenc package. You don't need it with XeLaTeX. – Phelype Oleinik Feb 16 '18 at 18:22
  • 1
    do not post a fragment that is "essentially" your document post a complete (small) document and post the exact error message copied from the log file that you get from the posted document, otherwise it is very hard to help. – David Carlisle Feb 17 '18 at 12:54
1

As others have already pointed out in the comments, your usage of \newfontfamily is incorrect. Instead of

\newfontfamily{Roboto}

it has to be like

\newfontfamily\Roboto{Roboto}

In the body of the document, you'd then write ... {\Roboto some text} ....

An MWE (minimum working example), which uses \setmainfont, \setsansfont, and three \newfontfamily statements (note that it's not always necessary to specify the ItalicFont, BoldFont, and BoldItalicFont options):

enter image description here

\documentclass{article}
\RequirePackage{fontspec}

\setmainfont{Minion Pro}
\setsansfont{Myriad Pro}

\newfontfamily\Roboto{Roboto}
\newfontfamily\RobotoCond{Roboto Condensed}
\newfontfamily\RobotoMed{Roboto Medium}%
        [ItalicFont     = "Roboto Medium Italic",
         BoldFont       = "Roboto Black",
         BoldItalicFont = "Roboto Black Italic"]

\newcommand\hello{Hello World.}
\newcommand\blurb{\hello{} \textbf{\hello} \textit{\hello} \textbf{\textit{\hello}}}

\begin{document}

\blurb

{\sffamily \blurb}

\medskip
{\Roboto \blurb}

{\RobotoMed \blurb}

{\RobotoCond \blurb}
\end{document}
  • 1
    Just for future reference: the new font family name does not have to be anything like the actual font name. \newfontfamily\beer{Roboto} works just as well, and would be invoked as {\beer This text is in Roboto font.} – user139954 Feb 17 '18 at 23:55
  • 1
    @RobtAll - In my answer, I was just applying what I understand to be established coding recommendations regarding how not to make one's code needlessly confusing, difficult to use, and prone to abuse. But, as you point out, if someone really prefers to name the macro that switches the font family to "Roboto" \beer (instead of \Roboto), there's absolutely nothing to stop them from doing so. I just hope I'll never have to debug their code -- \beer would probably be the least-problematic macro name that crops up... – Mico Feb 18 '18 at 8:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.