[Tex/LaTex] Create new paragraph style in LyX

lyxlyx-layoutsparagraphspreamble

Background

In OpenOffice and Microsoft Word it takes seconds to create a new paragraph style. Here is how I currently use LyX with the KOMA Script document class to mark text as a quotation:

  1. Type some text.
  2. Click the layouts drop-down.
  3. Click Quotation.

At this point, the text typed in step 1 is rendered as a quotation. The look of the quotation (for example, adding a border or changing its colour) can be altered by adding code to the preamble. All good here.

Problem

The Customization guide for LyX talks about adding a new document class, new styles, new layouts, etc. But the documentation does not say how to create a new text layout (like quotation) and have it show up in the menu.

I could create the new layout in the preamble, then insert LaTeX code before and after the text that I want to stylize. But that seems to run counter to how to wield LyX.

Question

  1. What is the formal name for the layouts in the drop-down? (Style, layout, template, paragraph style, etc.? It is difficult to search for something when the name seems to have several synonyms.)
  2. Without copying and pasting KOMA Script's .class file, what are the exact steps needed to add a new layout, such as a "warning" box, and make it available from the LyX drop-down?

For example:

  1. Create a new file called warning.inc.
  2. Copy the contents from pastebin.com/etc.
  3. Copy warning.inc into $HOME/.lyx/layouts.
  4. Update the document preamble as follows:
    \expandafter\def\expandafter\warning\expandafter{\warning\colorbox{}}
    
  5. Click Tools » Reconfigure.
  6. Restart LyX.
  7. Type some text.
  8. Click Warning from the drop down.
  9. Render the PDF to see the text in a box with a red border.

A simple, working example of steps, such as the above, to create a new "paragraph style" would be fantastic. Nearly all the documentation I have read shows how to set up a Document Class and define your own Templates (or Styles). Unless I have misunderstood something, I already have a Document Class: KOMA Script v2. I don't want to copy it (because if a new version is released, I have to merge if I upgrade): I want to extend it.

Thank you!

Best Answer

in the file stdlayouts.inc you can copy the definition for quotation to a part called "myquotation". In the file stdlists you can see at the end how additional preamble commands can be made which are hided from the normal user. After changing your layout file run reconfigure and restart lyx, there should now be a "myquoation" in all styles which support this kind of environment.

Here is an example for an LyX environment MyQuotation

Style MyQuotation
    Category              MainText
    Margin                Static
    LatexType             Environment
    LatexName             myquotation
    NextNoIndent          1
    LeftMargin            MMM
    RightMargin           MMM
    ParIndent             MM
    ParSkip               0
    ItemSep               0
    TopSep                0.5
    BottomSep             0.5
    ParSep                0
    Align                 Block
    AlignPossible         Block, Left, Right, Center
    Preamble
    \usepackage{mdframed}
    \usepackage{xcolor}
    \newenvironment{myquotation}
      {\begin{mdframed}[linecolor=red]\quotation}
      {\endquotation\end{mdframed}}
    EndPreamble
End

insert it into the file stdlayouts.inc and save the file in your local .lyx/layouts/ directory (don't know how it shopuld be on windows). Then run reconfigure and you shouöld see the paagraph layout MyQuotation which then gives a framed output. alt text