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?

2 Answers 2


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


I found a solution based on @scottkosty's answer! I put this in my ~/.lyx/external_templates folder, and then went to Insert > File > External Material and then select minted. It's not as well parametrized as it could be, but I don't have any more time to fiddle with this.

Template MintedSource
    GuiName "Minted Source Code"
        Run \inputminted{}
    InputFormat text
    FileFilter "*"
    AutomaticProduction true
    Preview InstantPreview
    Format PDFLaTeX
        Product "\\inputminted[linenos,fontsize=\\footnotesize,baselinestretch=1]{python}{$$AbsPath$$Basename$$Extension}"

        Requirement "underscore"
        Requirement "minted"

        UpdateFormat text
        UpdateResult "$$AbsPath$$Basename$$Extension"
        ReferencedFile text "$$AbsPath$$Basename$$Extension"
  • How do we specify linenos?
    – DavidR
    Commented Feb 18, 2017 at 22:09
  • Note that LyX will ship a minted external template with version 2.3.0. You are welcome to test the beta when it is out soon.
    – scottkosty
    Commented May 29, 2017 at 22:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .