I am using Windows as OS and TeXstudio as editor.
My project has the following structure:
-project
-main.tex
-chapter1
-chapter1.tex
-bibgraf.bib
-figures
-listings
-chapter2
-chapter2.tex
-bibgraf.bib
-figures
-listings
I am using the subfiles
package in order to compile independently the various chapters of my document. I would like to use the minted
package in each chapterN.tex
file in order to list the codes present in the listings
subdirectory of the chapterN
directory.
I am not sure whether this is actually possible with minted
, because it seems that it can only work with the root document directory according to what I have found here and here.
At the moment, compiling main.tex
using chapter1/listing/pythonfile.py
within \inputminted
succeeds, however this generates an error when I compile chapter1.tex
. The curious thing is that compiling chapter1.tex
using ./listing/pythonfile.py
has no effect on the output (the compilation seems to succeed bbut actually I do not notice any change in the .pdf output). Edit: I found out that for some reason the automatic update of the pdf output does not work anymore using minted
, problem observed also here.
Is there a solution for this issue? If not, is there an alternative to minted
that allows me to maintain the same project structure (and gives nice results with matlab and python codes possibly)? Edit: The issue remained is the fact that I have to use two different arguments for the inputminted
command when compiling main.tex
and chapter1.tex
.
Below my MWE.
Main.tex
\providecommand{\main}{.}
\documentclass[11pt,reqno]{amsart}
\usepackage{subfiles}
\newcommand{\onlyinsubfile}[1]{#1}
\newcommand{\notinsubfile}[1]{}
\usepackage{float}
\usepackage{graphicx}
\def\biblio{\bibliographystyle{amsalpha}\bibliography{\main/bibgraf}} % *Modification: added `\main/` to specify relative file location.
\graphicspath{{\main/figures/}}
\usepackage[justification=centering]{caption} % Centred captions
% Typesetting code
\usepackage[newfloat]{minted}
\captionsetup[listing]{position=top}
\newenvironment{longlisting}{\captionsetup{type=listing}}{}
\begin{document}
\def\biblio{}
\renewcommand{\onlyinsubfile}[1]{}
\renewcommand{\notinsubfile}[1]{#1}
Hallo main
\subfile{chapter1/chapter1}
\bibliographystyle{amsalpha}
\bibliography{chapter1/bibgraf}
\end{document}
chapter1.tex
%!TeX root = chapter1
\providecommand{\main}{..}
\makeatletter
\def\input@path{{\main/}}
\makeatother
\documentclass[\main/main.tex]{subfiles}
\graphicspath{
{"\main/chapter1/figures/"}
{"\main/\main/chapter1/figures/"}
}
\begin{document}
%% my chapter 1 content
Hallo, this is a test:
\begin{equation}
\label{eq:sec1:1}
\int dx =0
\end{equation}
This is a figure test:
\begin{figure}[h]
\includegraphics[width=0.5\textwidth]{example.pdf}
\end{figure}
\onlyinsubfile{this only appears if chapter1.tex is compiled (not when main.tex is compiled)}
\notinsubfile{this only appears if main.tex is compiled (not when chapter1.tex is compiled)}
This is a reference test: \cite{anderson}
This is a listing test:
\begin{longlisting}
\caption{Source code of \texttt{pythonfile.py}, where the main classes are defined.}
\inputminted[frame=single,xleftmargin=\parindent,linenos,breaklines,breakafter=_(\{\[\]]{python}{./listings/pythonfile.py}
\end{longlisting}\vspace{2cm}
\onlyinsubfile{Call reference}
\biblio
%%
\end{document}
subfiles 2019/10/25 v1.4
is able to handle locally included files (like images). There should be no need anymore to modify input and graphics pathes. This probably does not solve your issues, but the code should become simpler.