0

My hierarchy goes like this:

Main Folder
    SubFolderForCode(1)
        doc.tex
        code.py
    SubFolderForCode(2)
        doc.tex
        code.py
    SubFolderForDoc
        doc.tex

I want to import code from /SubFolderForCode(n)/code.py to /SubFolderForDoc/doc.tex via the \inputminted{python}{code.py} command, but unfortunately the code seems to be unreachable unless I add ../SubFolderForCode(n) before the actual code file name, which is understandably cumbersome. To work around this issue I used the import package as well:

/SubFolderForDoc/doc.tex
\import{../SubFolderForCode(n)/}{doc.tex}

/SubFolderForCode(n)/doc.tex
\inputminted{python}{code.py}

Unfortunately, even with the import package, I still seem to need preceding ../SubFolderForCode(n) before the actual code file name. So my question is:

How can I input code (via either minted or listings, though I would prefer minted) by writing the relative directory from /SubFolderForCode(n)/doc.tex, and then accumulating the /SubFolderForCode(n)/doc.tex files in one main file? The main file would preferably not be in the highest directory, and there are a lot of /SubFolderForCode(n)s.

  • simplest would be to use \def\mdir{/SubFolderForDoc}... \inputminted{python}{\mdir/code.py} (If you use some tex-level path search to find the file you have the complication of also passing the file location to pygments commandline which is possible, but this is a lot simpler if it is acceptable) – David Carlisle Apr 23 at 6:47
  • I agree that setting a macro would be the simplest solution, though I can't help but wonder if there is a way to set relative paths of relative paths...or something along those lines. – K. Paul Apr 23 at 14:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.