Ok, I have a set of structured data that I want to format consistently. In this case a set of spells for a role-playing game. Now in Latex I vaguely remember I could do something using \DeclareDocumentEnvironment but it's been a while and I want to do it in LyX.

So I want my final document to look like:


Casting Cost: 2CP
Casting Action: Instant
Range: Short
Deals 2d12 damage to target

Chain Lightning

Casting Cost: 1CP per target
Casting Action: Instant
Range: Medium
Chain lightning strikes through targets.
All targets must be within Short distance from each other.
Each target takes 1d6 damage

How do I go about setting something like this up? I want to achieve constant look and formatting throughout my document. I need a environment that takes multiple parameters.

I've really only used the more basic functions of Lyx before, like macro's for typing math (though I have used these functions alot_


My result using LyX first:

enter image description here

Step 1: Creating an environment (or command) with parameters in LaTeX

LyX is kind of a wrapper for LaTeX. So one needs to write the environment (or command) in LaTeX and should test it with a short LaTeX document. Exception: you are a LaTeX expert writing error-free LaTeX with perfect text layout. ;-)

There are restrictions on a LaTeX environment (or command) such that it can be easily mapped to a LyX style.

  • Only one parameter which is optional is allowed for the LaTeX environment.
  • Only two parameters with one of them optional are allowed for the LaTeX command.

Hence, in your case I would create a style (e.g. "MyTitle") for the title and one style for each detail. The last lines can be just plain text since no special format seems to be required.

Step 2: Creating a style in LyX

There must be a LyX style for each used environment (or command). These style definitions go into a .module-file. It should be placed in the layout folder of the lyx-tree in your home directory. LyX needs to be noticed about the new module. That is done by running Reconfigure of the LyX menu Tools and restarting LyX. Finally, for your document, under menu Document - Settings... - Modules add the new module (in the example "MyModule"). Now the new styles (e.g. "MyTitle") can be selected similar to "Section" or "Itemize".

Note: If an optional parameter is allowed for a LaTeX environment (or command) then it is denoted as "short title" in LyX. (That might come from the fact that a section heading can have optional parameter and its purpose is the short title). Furthermore, LyX maps it to the first LaTeX argument #1. Normal text is mapped to #2.

If no optional parameter is allowed, then LyX maps normal text to #1.

The folder lyx/layout of the LyX installation is a wealth of examples for definitions of styles, modules, and layouts. And the LyX section of "LyX, LaTeX and TeX" by Steve Litt might be worth reading.

Here is the LaTeX document for Step 1:

\newcommand{\mytitle}[1]{\bigskip\noindent\textbf{\large #1}\par\medskip}
\newcommand{\budget}[2][Dollar~]{\noindent\textbf{Budget:} #1#2\par}
\mytitle{A Beautiful Mind}\budget[\$]{58 million}
This movie is about John Nash.........

The module file MyModule.module for Step 2.

#Defines some styles for movies.....
#Author: me

Format 35

Style MyTitle
    Category              MyModule
    Margin                Static
    LatexType             Command
    LatexName             mytitle
    NextNoIndent          1
    TopSep                1.3
    BottomSep             0.7
    Align                 Block
      Series              Bold
      Size                Larger
    OptionalArgs          0
      \newcommand{\mytitle}[1]{\bigskip\noindent\textbf{\large #1}\par\medskip}

Style Budget
    Category              MyModule
    LatexType             Command
    Margin                First_Dynamic
    LatexName             budget
    LabelType             Static
    LabelString           "Budget:"
    NextNoIndent          1
    LabelSep              xx
    ParIndent             MMM
    ParSkip               0.4
    ItemSep               0.2
    TopSep                0.7
    BottomSep             0.7
    ParSep                0.3
    Align                 Block
    AlignPossible         Left
    OptionalArgs          1
      Shape               Up
      Series              Bold
      \newcommand{\budget}[2][Dollar~]{\noindent\textbf{Budget:} #1#2\par}

And the LyX document to generate the above image:

#LyX 2.0 created this file. For more info see http://www.lyx.org/
\lyxformat 413
\textclass article
\use_default_options true
\maintain_unincluded_children false
\language english
\language_package default
\inputencoding auto
\fontencoding global
\font_roman default
\font_sans default
\font_typewriter default
\font_default_family default
\use_non_tex_fonts false
\font_sc false
\font_osf false
\font_sf_scale 100
\font_tt_scale 100

\graphics default
\default_output_format default
\output_sync 0
\bibtex_command default
\index_command default
\paperfontsize 12
\spacing single
\use_hyperref false
\papersize default
\use_geometry false
\use_amsmath 1
\use_esint 1
\use_mhchem 1
\use_mathdots 1
\cite_engine basic
\use_bibtopic false
\use_indices false
\paperorientation portrait
\suppress_date false
\use_refstyle 1
\index Index
\shortcut idx
\color #008000
\secnumdepth 3
\tocdepth 3
\paragraph_separation indent
\paragraph_indentation 0pt
\quotes_language english
\papercolumns 1
\papersides 1
\paperpagestyle default
\tracking_changes false
\output_changes false
\html_math_output 0
\html_css_as_file 0
\html_be_strict false


\begin_layout MyTitle
A Beautiful Mind

\begin_layout Budget
\begin_inset Argument
status open

\begin_layout Plain Layout


58 million

\begin_layout Standard
This movie is about John Nash.........



Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.