[Tex/LaTex] Using \inputminted from lyx with relative path

lyxlyx-layoutsminted

I'm using the minted package with lyx. I want to use \inputminted and must be able to specify a relative path (to share between machines with different home directory names).

The problem is that the working directory when \inputminted is invoked is /tmp/lyxbuf_tmp. This mailing list post from 2009 discusses this exact problem of copying external material to this directory, but there appears to be no resolution that I can find.

Can anyone explain how to make a minted.layout file which would allow me to use \inputminted and have the desired effect of including an external source code file?

Alternatively can anyone suggest any ways to achieve the desired effect?

Best Answer

Here are two ways:

Create an external variable template.

This is the best way but will take some time to understand and set up. Go to Tools > Customization > Section 6 (Including External Material)

There are many path variables. For example:

$$AbsOrRelPathParent The file path, absolute or relative to the LyX document.
$$FPath The path part of $$FName (absolute name or relative to the LyX document).
$$RelPathMaster The file path, relative to the master LyX document.
$$RelPathParent The file path, relative to the LyX document.

Use a script (e.g. Python or Bash) to do the substitution.

This is a little hackish but gives you complete control. Make a converter (again, see the Customization manual for details) by going to Tools > Preferences > File Handling > Converters. Edit the converter field. See the following screenshot: enter image description here

Related Question