Nodejs - Executing Pandoc Command for LaTeX
10/10/2021, SunEnsuring Consistent Execution Path
In this example, a script might refer to a file, index.tex, which is referenced by Pandoc to convert a file located within a folder:
/contents
index.tex
spawn('pandoc', [
'/the/full/path/to/contents/index.tex',
'-o',
'/the/full/path/to/output/index.html',
'-s'
]);
When you wish to have a more maintainable writing experience, one can break up the contents of the 'index.tex' into multiple .tex files and place them into a different folder.
The index.tex file will reference the 'chapter-01.tex' file inside the new 'chapters' folder:
/contents
/chapters
chapter-01.tex
index.tex
% chapter-01.tex
\chapter{Chapter 1}
\section{section}
Some section content.
% index.tex
\documentclass{article}
\title{Tex}
\begin{document}
\input{chapters/chapter-01}
\end{document}
However, when you refer to Pandoc inside a script to perform the execution, the reference path might not have been what you have expected. If you refer to the file, index.tex, from a directory outside from where the index.tex is located, Pandoc will not render the \input
command (the command to include content from other files) properly.
There will be a need to change to location to where the index.tex file is situated for Pandoc to recognize the proper path for execution.
// Before executing the pandoc command, change into the index.tex directory.
process.chdir('/the/full/path/to/content');