I wish to use the url package with the hyphens option and the hyperref package. Because the hyperref package loads the url package, I have to pass the hyphens option to the url package before it is load. So I need to place the code


before the Lyx-generated component of the preamble. How do I do that?

Please note:

  • I am aware that I could load the hyperref package in the preamble (and disable it in the interface). I'm trying to avoid this as this defeats the point of Lyx. I'm also looking to Lyx as a more user-friendly tool for my institute than directly tex-coding.
  • I am aware of the breaklinks option for the hyperref package but that requires overriding automatic identification of drivers (to force it to use the pdftex driver).

EDIT: Feature request has been lodged with Lyx development team at: https://www.lyx.org/trac/ticket/10567

  • My only suggestion is what you already said: disable hyperref in LyX and load it yourself. I know that's not ideal though. If you have an idea for how LyX could make this easier, please make an enhancement request at lyx.org/trac
    – scottkosty
    Feb 17, 2017 at 2:07
  • I've followed through on your suggestion
    – Charlie
    Feb 17, 2017 at 7:29

2 Answers 2


In order to achieve the output you want, add the following to Document > Settings > Local Layout:

PackageOptions url hyphens
Requires url

Hit "Validate" and "Apply", and you're done.


In general, the only way (currently) to gain access to the part between \documentclass and the first packages that are loaded is to write your own layout:

  1. Find the one that most suits your needs. Let's say Memoir:

    enter image description here

  2. Find the accompanying .layout inside your LyX layout folder:

    enter image description here

    Make a copy of this and call it (say) myclass.layout.

  3. Edit myclass.layout, making sure the first three lines look like this:

    #% Do not delete the line below; configure depends on this
    #  \DeclareLaTeXClass[myclass]{MyCLaSS}
    #  \DeclareCategory{Books}

    The optional argument for \DeclareLaTeXClass - myclass here - will point to a class that you'll write called myclass.cls. The mandatory argument - MyCLaSS here - will point to the list entry under Document Class within LyX. The mandatory argument for \DeclareCategory points to the category under which MyCLaSS will appear within the Document Class list.

  4. Create myclass.cls:

    \Providesclass{myclass}[My custom class]

    See Difference between \LoadClass and \LoadClassWithOptions. Also include whatever you want additionally here, like


    Store this file somewhere within your TEXMF local tree:

    enter image description here

    See Where do I place my own .sty or .cls files, to make them available to all my .tex files?

  5. Run texhash to update your filename database.

  6. In LyX, run Tools > Reconfigure.

    enter image description here

  7. Restart LyX.

  8. Create a new document and Document > Settings... > Document Class and choose your MyCLaSS:

    enter image description here

  • 1
    It's an impressive amount of effort you've gone to, but I feel the correct answer is actually '"you can't". Writing your own layout files to me is more contrary to the point of Lyx then writing your own preamble.
    – Charlie
    Feb 17, 2017 at 7:31
  • 1
    @Charlie: Well, LyX is extendable in this way. Until a feature request for something alternative is made available, I'm guessing this is a viable LyX-like solution.
    – Werner
    Feb 17, 2017 at 7:40

You must log in to answer this question.

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