Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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:

Fireball

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_

share|improve this question
add comment

1 Answer

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:

\documentclass[12pt]{article}
\setlength{\parindent}{0pt}
\newcommand{\mytitle}[1]{\bigskip\noindent\textbf{\large #1}\par\medskip}
\newcommand{\budget}[2][Dollar~]{\noindent\textbf{Budget:} #1#2\par}
\begin{document}
\mytitle{A Beautiful Mind}\budget[\$]{58 million}
This movie is about John Nash.........
\end{document}

The module file MyModule.module for Step 2.

#\DeclareLyXModule{MyModule}
#DescriptionBegin
#Defines some styles for movies.....
#DescriptionEnd
#Author: me

Format 35

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

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
    LabelFont
      Shape               Up
      Series              Bold
    EndFont
    Preamble
      \newcommand{\budget}[2][Dollar~]{\noindent\textbf{Budget:} #1#2\par}
    EndPreamble
End

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
\begin_document
\begin_header
\textclass article
\use_default_options true
\begin_modules
MyModule
\end_modules
\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
\end_index
\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
\end_header

\begin_body

\begin_layout MyTitle
A Beautiful Mind
\end_layout

\begin_layout Budget
\begin_inset Argument
status open

\begin_layout Plain Layout
$
\end_layout

\end_inset

58 million
\end_layout

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

\end_layout

\end_body
\end_document
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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