0

My project file structure is:

C:\USERS\NAME\MULTIFILE_MWE
│   main.tex
│
├───pgf
│       data.csv
│       pgftikz_fig.tex
│
└───sections
        section_import.tex

My requirements are:

  • main.tex file brings together many sections.
  • Each section compiles independently and calls on pgf code stored in ./pgf/.
  • Each pgf file compiles independently and reads .csv.

I can compile pgftikz_fig.tex independently and I can compile section_import.tex independently. I cannot compile main.tex.

Data

data.csv

a,b,c,d
1,4,5,1
2,3,1,5
3,5,6,1
4,1,4,9
5,3,4,7

PGF plot file

% pgftikz_fig.tex
\documentclass[crop=false]{standalone}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot table [x=a, y=c, col sep=comma] {./pgf/data.csv};
\end{axis}
\end{tikzpicture}

\end{document}

Master file

% main.tex
\documentclass{article}
\usepackage[subpreambles=true]{standalone}
\usepackage{import}

\begin{document}

\import{sections/}{section_import}

\end{document}

Section file

% section_import.tex
\documentclass[crop=false]{standalone}
\usepackage[subpreambles=true]{standalone}
\usepackage{import}

\begin{document}

\subimport{./pgf/}{pgftikz_fig.tex}

\end{document}
Sav-econ
  • 335

1 Answers1

0

Solution using \subimport

In the main.tex file I should use \subimport not \import

% main.tex
\documentclass{article}
\usepackage[subpreambles=true]{standalone}
\usepackage{import}

\begin{document}

\subimport{sections/}{section_import}

\end{document}

In the section_import.tex file I should use the correct file pointer ../ not ./

% section_import.tex
\documentclass[crop=false]{standalone}
\usepackage[subpreambles=true]{standalone}
\usepackage{import}

\begin{document}

\subimport{../pgf/}{pgftikz_fig}

\end{document}

Solution using \input

main.tex will compile if section_import.tex uses \input rather than \subimport:

\documentclass[crop=false]{standalone}
\usepackage[subpreambles=true]{standalone}

\begin{document}

\input{./pgf/pgftikz_fig.tex}

\end{document}

However I prefer to use the import package because my full project is more complex than the minimal example I have provided. In the full project I reference figures and I have citations within each section. input is less powerful for this than import.

Sav-econ
  • 335
  • I found this answer useful https://tex.stackexchange.com/a/58485/46516. I do not know the difference between \subimport and \subimport*. – Sav-econ Apr 19 '20 at 17:19
  • 1
    There is absolutely no difference now; the star versions are accepted so old documents can be processed. – Donald Arseneau Apr 19 '20 at 17:40
  • Since the directory contents aren't hierarchical (nested), and there are no repeated file names, it may be easier to specify \makeatletter \input@path{{sections/}{pgf/}} \Ginput@path{{sections/}{pgf/}}, and then use simple \input{pgftikz_fig} and \input{section_import}. – Donald Arseneau Apr 19 '20 at 17:51