3

I'm trying to figure out how one could input markdown files recursively. I'm using the markdown package and it does allow inputting files with /markdownInput. This works for the moment but in my writing process I often switch the order of sections (creative thinking :P). If this happens I have to rename the files and also fix the markdownInput in my thesis.tex.

Right now I'm using the pdflatex compiler because it is the "default" of my university document class. As far as I understand I could write my own function in Lua to do that if I'd use the LuaLatex compiler. I did try to switch to the lualatex compiler but it throws a lot of error messages. Because of that I try to stay away from changing it.

Is there also a way to do that with pdflatex?

My structure of my thesis is

/chapter01/00_index.md
/chapter01/01_research_objective.md
/chapter01/02_research method.md
/chapter02/00_index.md
/chapter02/01_theory_of_world_domination.md
thesis.tex

It would be great to have a recursive function to add all files recursively to the document. So that I only have to maintain the order of the folders and files.

3
  • 3
    just run a command such as find . -name \*.md > files.tex before you run pdflatex then you can process that list of files easily in tex (similar commands are available on windows) Commented Mar 6, 2020 at 13:38
  • 1
    this is finding all graphics to include rather than all markdown but is essentially the same: tex.stackexchange.com/questions/161111/… Commented Mar 6, 2020 at 13:41
  • If you can spend some time figuring how it works (not too much), bookdown is exactly what you are asking for (and yes, that you have to use your university LaTeX class --- or any other --- is not a problem.) Commented Mar 6, 2020 at 18:52

1 Answer 1

1

Credits to David Carlisle :)

I created toc.sh which gets executed before latexmk. As I'm using the Latex-Workshop extension for VSCode, I had to put a time check in the script otherwise latexmk is in loop.

thesis.tex:

\begin{document}
\input{toc.tex}
\end{document}
...

toc.sh:

# Create only toc.tex if it's older than 3 seconds
if test `find "toc.tex" -mmin +0.05`
then
    find . -name \*.md | sed -e "s/.*/\\\\markdownInput{\\0}/" | sort > toc.tex
fi

settings.json:

"latex-workshop.latex.recipes": [
    {
      "name": "Generate TOC from files & latexmk",
      "tools": [
        "toc",
        "latexmk"
      ]
    }
  ],
"latex-workshop.latex.tools": [
    {
      "args": [
        "--shell-escape",
        "-interaction=nonstopmode",
        "-file-line-error",
        "-pdf",
        "%DOC%"
      ],
      "command": "latexmk",
      "name": "latexmk"
    },
    {
      "command": "./toc.sh",
      "name": "toc"
    }
  ],

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.