1

I have a document with a very long preamble in the separate file general.tex. The main.tex looks something like

\documentclass[10pt, letterpaper]{article}

\input{general.tex}

\usepackage{subfiles}

\begin{document}

\end{document}

In general I set my main files as Arial with ttf files that looks something like

\setsansfont[
BoldFont=ARIAL/arialbd.ttf,
ItalicFont=ARIAL/ariali.ttf,
BoldItalicFont=ARIAL/arialbi.ttf
]{ARIAL/arial.ttf}

and when compiling main.tex it appears as it should but when trying to compile subfiles the formatting from the preamble is gone. I'm not sure if it is every setting in general.tex and am working on checking but the most obvious is the lack of Arial. What am I doing wrong and how do I fix this? Thanks so much!

Complete example: general.tex

%----------------------------------------------------------------------------------------
%   Packages
%----------------------------------------------------------------------------------------

% Necessary
\usepackage[german,english]{babel} % English and German language 
\usepackage{booktabs} % Horizontal rules in tables 
% For generating tables, use “LaTeX” online generator (https://www.tablesgenerator.com)
\usepackage{comment} % Necessary to comment several paragraphs at once
% \usepackage[utf8]{inputenc} % Required for international characters
% ^ no longer required outdated package

\usepackage[T1]{fontenc} % Required for output font encoding for international characters


% Might be helpful
\usepackage{amsmath,amsfonts,amsthm} % Math packages which might be useful for equations
\usepackage{tikz} % For tikz figures (to draw arrow diagrams, see a guide how to use them)
\usepackage{tikz-cd}
\usetikzlibrary{positioning,arrows} % Adding libraries for arrows
\usetikzlibrary{decorations.pathreplacing} % Adding libraries for decorations and paths
\usepackage{tikzsymbols} % For amazing symbols ;) https://mirror.hmc.edu/ctan/graphics/pgf/contrib/tikzsymbols/tikzsymbols.pdf 
\usepackage{blindtext} % To add some blind text in your paper
\usepackage{multicol}
\usepackage{gensymb}
\usepackage{fontspec}

\setsansfont[
BoldFont=ARIAL/arialbd.ttf,
ItalicFont=ARIAL/ariali.ttf,
BoldItalicFont=ARIAL/arialbi.ttf
]{ARIAL/arial.ttf}

\usepackage{wrapfig}

% From Alex Cong
% Easy quotation marks, \say{ex.} - \say{\say{ex.}}}
\usepackage{dirtytalk}
% Easy comment large sections \bigcomment{large section}
\newcommand{\bigcomment}[1]{}

%---------------------------------------------------------------------------------
% Additional settings
%---------------------------------------------------------------------------------

%---------------------------------------------------------------------------------
% Define your margins
\usepackage{geometry} % Necessary package for defining margins

\geometry{
    top=2cm, % Defines top margin
    bottom=2cm, % Defines bottom margin
    left=2.2cm, % Defines left margin
    right=2.2cm, % Defines right margin
    includehead, % Includes space for a header
    %includefoot, % Includes space for a footer
    %showframe, % Uncomment if you want to show how it looks on the page 
}

\setlength{\parindent}{15pt} % Adjust to set you indent globally 

%---------------------------------------------------------------------------------
% Define your spacing
\usepackage{setspace} % Required for spacing
% Two options:
\linespread{1.5}
%\onehalfspacing % one-half-spacing linespread

%----------------------------------------------------------------------------------------
% Define your fonts
\usepackage[T1]{fontenc} % Output font encoding for international characters}

% \usepackage[utf8]{inputenc} % Required for inputting international characters
% ^ no longer required


\usepackage{XCharter} % Use the XCharter font



%---------------------------------------------------------------------------------
% Define your headers and footers

\usepackage{fancyhdr} % Package is needed to define header and footer
\pagestyle{fancy} % Allows you to customize the headers and footers

%\renewcommand{\sectionmark}[1]{\markboth{#1}{}} % Removes the section number from the header when \leftmark is used
\pagestyle{fancy}
\fancyhf{}
\rhead{}
\lhead{2021-2022 Design Report}
\rfoot{Page \thepage}

% Headers
% \lhead{} % Define left header
% \chead{\textit{}} % Define center header - e.g. add your paper title
%\chead{}
% \rhead{} % Define right header

% Footers
% \lfoot{} % Define left footer
% \cfoot{\footnotesize \thepage} % Define center footer
% \rfoot{} % Define right footer

%---------------------------------------------------------------------------------
%   Add information on bibliography
\usepackage{natbib} % Use natbib for citing
\usepackage{har2nat} % Allows to use harvard package with natbib https://mirror.reismil.ch/CTAN/macros/latex/contrib/har2nat/har2nat.pdf

% For citing with natbib, you may want to use this reference sheet: 
% http://merkel.texture.rocks/Latex/natbib.php
\usepackage{pdfpages}
%---------------------------------------------------------------------------------
% Add field for signature (Reference: https://tex.stackexchange.com/questions/35942/how-to-create-a-signature-date-page)
\newcommand{\signature}[2][5cm]{%
  \begin{tabular}{@{}p{#1}@{}}
    #2 \\[2\normalbaselineskip] \hrule \\[0pt]
    {\small \textit{Signature}} \\[2\normalbaselineskip] \hrule \\[0pt]
    {\small \textit{Place, Date}}
  \end{tabular}
}

main.tex

%{
% Credits are indicated where needed. The general idea is based on a template by Vel ([email protected]) and Frits Wenneker.

\documentclass[10pt, letterpaper]{article} % General settings in the beginning (defines the document class of your paper)
% 10pt = is the font size
% Letter is the paper size
% “article” is your document class

%\setlength\parskip{1em plus 0.1em minus 0.2em}
% if you want automatically change spacing between paragraphs

\input{general.tex} % Loads required packages from the separate file 
\usepackage{amsmath}

% \usepackage[utf8]{inputenc}
% Outdated package

\usepackage{listings}
\usepackage{xcolor,colortbl}
\usepackage{graphicx}
\usepackage{lscape}
\usepackage{float}
\floatplacement{figure}{H}
\floatplacement{table}{H}
\usepackage{caption}
\usepackage{subcaption}
\definecolor{codegreen}{rgb}{0,0.6,0}
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
\definecolor{codepurple}{rgb}{0.58,0,0.82}
\definecolor{backcolour}{rgb}{0.95,0.95,0.92}

\lstdefinestyle{mystyle}{
    backgroundcolor=\color{backcolour},   
    commentstyle=\color{codegreen},
    keywordstyle=\color{magenta},
    numberstyle=\tiny\color{codegray},
    stringstyle=\color{codepurple},
    basicstyle=\ttfamily\footnotesize,
    breakatwhitespace=false,         
    breaklines=true,                 
    captionpos=b,                    
    keepspaces=true,                 
    numbers=left,                    
    numbersep=5pt,                  
    showspaces=false,                
    showstringspaces=false,
    showtabs=false,                  
    tabsize=2
}

\lstset{style=mystyle}

%}
%---------------------------------------------------------------------------------
%   General information
%---------------------------------------------------------------------------------
\title{} % Adds your title
\author{}
% \author{Chris Hayner, Caroline Paxton, Howard Peng, Max Mcgowan  % Add your first and last name
    %\thanks{} % Adds a footnote to your title
    %\institution{YOUR INSTITUTION} % Adds your institution
%   }

% \date{December 7, 2020} % Adds the current date to your “cover” page; leave empty if you do not want to add a date


%---------------------------------------------------------------------------------
%   Define what’s in your document
%---------------------------------------------------------------------------------
\setcounter{tocdepth}{2}
\setlength{\parindent}{0pt}
\usepackage[titles]{tocloft}

\usepackage{subfiles}

\begin{document}
% If you want a cover page, uncomment "\input{content/0A-coverpage}" and comment "\maketitle" as well as "\input{content/0B-disclaimer}"

%\maketitle % Print your title, author name and date; comment if you want a cover page 
%\input{content/0A-coverpage} % Adds a cover page; uncomment if you want a cover page
% \input{content/0B-disclaimer} % Gives you the word count; comment if you want a cover page 
%\input{content/0C-toc} % Adds a table of content; uncomment if required

% Make sure to use XeLaTeX, TeX Live version 2021
\setmainfont{Arial}

\newpage
%\includepdf[pages = {1}]{Figures/CoverPage.pdf}
\input{Content/1 - Abbreivations Figures TOC}
\subfile{Content/2 - Executive Summary}
\subfile{Content/3 - Management Summary}
\subfile{Content/4 - Conceptual Design}
\subfile{Content/5 - Preliminary Design}
\subfile{Content/6 - Detailed Design}
\subfile{Content/7 - Manufacturing Plan}
\subfile{Content/8 - Test Plan}
\subfile{Content/9 - Performance Results}
\input{Content/10-Reference.tex}



%---------------------------------------------------------------------------------

\end{document}

Sample subfile 2 - Executive Summary.tex

%\section{Executive Summary}

\documentclass[../main.tex]{subfiles}
% \graphicspath{{\subfix{../images/}}}
\begin{document}

\section{Executive Summary}
\blindtext
\end{document}
2
  • Welcome to TeX.SX! Can you please provide a complete example, main file and subfile, that we can typeset and that illustrates your problem? In general, putting the preamble into a separate file works. At the moment, you do not provide enough information to give a meaningful answer.
    – gernot
    Jan 31 at 16:10
  • 1
    If my answer solves your problem, your question is a prime example for why it is important to provide a complete document illustrating the issue, and not just the information one deems relevant. From your original question, it is impossible to guess the source of the problem.
    – gernot
    Feb 2 at 16:30

1 Answer 1

1

I was able to typeset your document on Linux (TeXlive) and Windows (MikTeX) after the following changes, with both main and subfile using the same Arial-like sans serif font.

  1. Move the command

    \setmainfont{Arial}
    

    to a place where it will be executed when typesetting the main file and the subfile. At the moment, it is only executed for the main file, but ignored for the subfiles. Move it e.g. immediately before \begin{document}, or into general.tex.

  2. In general.tex, comment out the line

    \usepackage{XCharter} % Use the XCharter font
    

    On both systems, Linux and Windows, I get an error message about a conflict with the fontspec package. Probably this package is not needed anyway, given that you are intending to use a sans-serif font, while XCharter has serifs.

  3. On both of my systems, there are no fonts ARIAL/arial*.ttf installed, so in general.tex, I commented out the lines

    \setsansfont[
    BoldFont=ARIAL/arialbd.ttf,
    ItalicFont=ARIAL/ariali.ttf,
    BoldItalicFont=ARIAL/arialbi.ttf
    ]{ARIAL/arial.ttf}
    

I suggest to perform the same changes, to verify that both main and subfile come out in the same Arial-like font, and then reintroduce font commands if needed (while checking the log for errors).

Debugging: As the subfiles package adds an extra layer of complexity, it may help, in case of errors, to ensure first that the subfile typesets correctly without subfiles. In a copy of the subfile (at the same location),

  1. replace the line \documentclass...{subfiles} by the preamble of the main file, including its \documentclass command.

  2. make sure that the paths are corrected; e.g., in your sample document replace \input{general.tex} by \input{../general.tex}.

If the problem also occurs with this copy (here: does not typeset in the correct font), then the issue is not related to using subfiles, but lies somewhere else. If, on the other hand, the modified copy runs without problems, then there is probably an issue with some file path. See section 3.2 of the documentation on hints how to fix it.

Last word: consider not using the subfiles package. In many cases, it works just as well by having a list of \input statements in the main file and then commenting out those that should not be typeset.

2
  • This change made it so none of the files loaded in Arial.
    – Alex Cong
    Feb 4 at 2:20
  • My first answer actually was a bit brief, concentrating on what I thought was essential. Hope you get a step further now.
    – gernot
    Feb 5 at 13:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .