# Cannot set custom fontsize on minted package after setting custom sans font using fontspec

\documentclass[11pt]{article}
\usepackage{minted}
\usepackage{fontspec}

\defaultfontfeatures[CalibriLight]{
Extension      = .TTF                     ,
UprightFont    = fonts/Calibri-Light      ,
ItalicFont     = fonts/Calibri-Light-Italic   ,
BoldFont       = fonts/Calibri-Light-Bold     ,
BoldItalicFont = fonts/Calibri-Light-Bold-Italic
}

\defaultfontfeatures[Calibri]{
Extension      = .TTF                             ,
UprightFont    = fonts/Calibri-Light-Bold             ,
ItalicFont     = fonts/Calibri-Light-Bold-Italic  ,
BoldFont       = fonts/Calibri-Bold                   ,
BoldItalicFont = fonts/Calibri-Bold-Italic
}

\newfontfamily{\calibri}[Scale=1.2]{Calibri}
\setsansfont[Scale=1.2]{CalibriLight}

\setminted[matlab]{linenos=true, frame=single, framesep=5pt, fontsize=10pt}

\begin{document}
\inputminted{matlab}{file.m}
\end{document}


I've left in only the part of the source that's relevant to my problem, I've created a custom font because I need to use Calibri for my report section/subsection headings.

The source above gives errors, but it works fine if I set fontsize to something like \small instead of a value like 10pt.

These are the contents of file.m: clear 'all' clc load foobar; soundsc(foobar1, 8000); %soundsc(foobar1, 4000); %soundsc(foobar1, 2000);

And this is the error I get:

! LaTeX Error: Something's wrong--perhaps a missing \item.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.8 \end{Verbatim}
Try typing <return> to proceed.
If that doesn't work, type X <return> to quit.
! LaTeX Error: Something's wrong--perhaps a missing \item.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.8 \end{Verbatim}
Try typing <return> to proceed.
If that doesn't work, type X <return> to quit.
)
Overfull \hbox (38.29774pt too wide) in paragraph at lines 1--28
[]\TU/lmr/m/n/10.95 10pt[][][]
[]
[1
] (test.aux) )


The line numbers will match with the source I've provided above, and as I mentioned earlier, simply changing the fontsize to \small instead of 10pt fixes the issue, but it doesn't achieve what I require.

Thanks in advance for any help.

• Welcome to TeX.SX! Apr 16, 2018 at 13:52
• what error do you get (and does it depend on file.m (which we don't have) Apr 16, 2018 at 16:17
• @DavidCarlisle I have updated my post with the information you require, please let me know of anything else you require and I will update my post as necessary. Thank you for any and all help! Apr 17, 2018 at 5:54

You're misusing \defaultfontfeatures:

\newfontfamily{\calibrilight}{Calibri-Light}[
Extension      = .TTF,
Path           = ./fonts/,
Scale          = 1.2,
UprightFont    = *,
ItalicFont     = *-Italic,
BoldFont       = *-Bold,
BoldItalicFont = *-Bold-Italic,
]

\setsansfont{Calibri}[
Extension      = .TTF,
Path           = ./fonts/,
Scale          = 1.2,
UprightFont    = *-Light-Bold,
ItalicFont     = *-Light-Bold-Italic,
BoldFont       = *-Bold,
BoldItalicFont = *-Bold-Italic,
]


Complete example (but using ClearSans as I don't own Calibri); adjust the font names to suit you.

\begin{filecontents*}{\jobname.m}
clear 'all'
clc
soundsc(foobar1, 8000);
%soundsc(foobar1, 4000);
%soundsc(foobar1, 2000);
\end{filecontents*}

\documentclass[11pt]{scrartcl}
\usepackage{minted}
\usepackage{fontspec}
\usepackage{lipsum}

\newfontfamily{\calibrilight}{ClearSans}[
%  Extension      = .TTF,
%  Path           = ./fonts/,
Scale          = 1.2,
UprightFont    = *,
ItalicFont     = *-Italic,
BoldFont       = *-Bold,
BoldItalicFont = *-BoldItalic,
]

\setsansfont{ClearSans}[
%  Extension      = .TTF,
%  Path           = ./fonts/,
Scale          = 1.2,
UprightFont    = *-Medium,
ItalicFont     = *-MediumItalic,
BoldFont       = *-Bold,
BoldItalicFont = *-BoldItalic,
]

\setminted[matlab]{linenos=true, frame=single, framesep=5pt, fontsize=\small}

\begin{document}

\section{This is in ClearSans}

\lipsum[1]

Normal sans: {\sffamily Whatever \textbf{bold}}

Light sans: {\calibrilight Whatever \textbf{bold}}

\inputminted{matlab}{\jobname.m}

\end{document}

• Would you please explain to me how I misused it? I tried replacing the default font features portion with the block you answered with which gave me more errors... On another note, what I wanted to accomplish is setting Calibri-Light as my default sans font family and having a custom font family for Calibri which I used for my section headings. Apr 17, 2018 at 13:41
• @Romtromon I'm not sure I follow you; the options you gave for \defaultfontfeatures are proper of \setXfont or \newfontfamily. Since I don't own Calibri Light, I can't test. Apr 17, 2018 at 14:02
• @Romtromon There was a typo that caused errors: the final } should have been ]. Apr 17, 2018 at 14:17
• Thank you for the clarification, but my issue sadly isn't solved yet. The script compiles fine when the fontsize is set to \small for minted but not when I set it to a value like 10pt, which is what I want to do. I am also unsure of why you included the package lipsum, I did not do that. Apr 17, 2018 at 15:23
• @Romtromon You can't do fontsize=10pt; the only admissible values are font size changing commands such as \small. If the overall font size is 11pt (like in your case), \small chooses 10pt size. The lipsum package is just for providing filler text. Apr 17, 2018 at 15:24