From charlesreid1

LyX is a WYSIWYM (What You See Is What You Mean) LaTeX editor. The homepage is at http://www.lyx.org.


Tips and Tricks

Compiling a Document With Multiple Files

As documents grow larger, it is much more convenient to split these documents up into multiple LyX files. These can be combined into a single document by creating a "master" LyX file, which includes each LyX file. This master file typically contains any macros along with the table of contents, includes each chapter or file, any appendices, and finally, the bibliography.

Each chapter can be edited individually, but if macros are defined in the master document, they will be broken if the LyX file for that chapter is opened alone. In order to fix this, open the master document - this should immediately fix the broken macros.


Customizing LyX

Determining where LyX Data Directory is

Open LyX, click LyX > About LyX, and look for the "User Directory". This is the directory where all data (bind files, UI files, layouts, etc.) should go.

Create a Bind File

The bind file, located at /Path/To/LyX/Data/Directory/bind, can be used to define or re-define keyboard shortcuts.

Some customizations that I have made in my LyX bind file are included below.

Install a Bind File

To actually install/use the bind file, you should create a new file like my_shortcuts.bind in the user data directory (see "Determining Where LyX Data Directory Is" above for how to find this directory).

Finally, open LyX and click LyX > Preferences. Open the Editing > Shortcuts preference panel. In the text box at the top, labeled Bind File, enter the name of the bind file without the .bind extension, e.g., my_shortcuts.

The shortcuts should be ready to go as soon as you save your preferences.


LyX 2.2.x

Just a few modifications - importing the mac bind file, and including some additional keyboard navigation shortcuts (these are also in mac.bind but whatevs).

# This is my own bind file.
# Charles Reid.

\bind_file mac.bind

# (cmd + , is show global lyx settings)
# cmd + shift + ,   show document settings
\bind "C-S-,"       "dialog-show document"


# Force LyX to exhibit normal mac behavior of
# alt + left = left 1 word
# alt + right = right 1 word
# (this is necessary because setting this in LyX > Preferences > Control > "Use Mac-style for cursor moving between words" doesn't work)
\bind "A-Right"                      "word-right"
\bind "S-A-Right"                    "word-right-select"
\bind "A-Left"                       "word-left"
\bind "S-A-Left"                     "word-left-select"
\bind "A-Up"                         "paragraph-up"
\bind "S-A-Up"                       "paragraph-up-select"
\bind "A-Down"                       "paragraph-down"
\bind "S-A-Down"                     "paragraph-down-select"


# ------------- straight from mac.bind ----------------

#  +: "Command-Right Arrow"          # Move the text insertion point to the end of the current line
\bind "C-Right"                      "line-end"
#  +: "Command-Left Arrow"           # Move the text insertion point to the beginning of the current line
\bind "C-Left"                       "line-begin"
#  +: "Command-Down Arrow"           # Move the text insertion point to the end of the document
\bind "C-Down"                       "buffer-end"
\bind "M-A-Down"                     "inset-end"
#  +: "Command-Up Arrow"             # Move the text insertion point to the beginning of the document
\bind "C-Up"                         "buffer-begin"
\bind "M-A-Up"                       "inset-begin"
#  +: "Shift-Command-Right Arrow"    # Select text between the insertion point and the end of the current line (*)
\bind "S-C-Right"                    "line-end-select"
#  +: "Shift-Command-Left Arrow"     # Select text between the insertion point and the beginning of the current line (*)
\bind "S-C-Left"                     "line-begin-select"
#  +: "Shift-Right Arrow"            # Extend text selection one character to the right (*)
\bind "S-Right"                      "char-right-select"
#  +: "Shift-Left Arrow"             # Extend text selection one character to the left (*)
\bind "S-Left"                       "char-left-select"
#  +: "Shift-Command-Up Arrow"       # Select text between the insertion point and the beginning of the document (*)
\bind "S-C-Up"                       "buffer-begin-select"
#  +: "Shift-Command-Down Arrow"     # Select text between the insertion point and the end of the document (*)
\bind "S-C-Down"                     "buffer-end-select"
#  +: "Shift-Up Arrow"               # Extend text selection to the line above, to the nearest character boundary at the same horizontal location (*)
\bind "S-Up"                         "up-select"
#  +: "Shift-Down Arrow"             # Extend text selection to the line below, to the nearest character boundary at the same horizontal location (*)
\bind "S-Down"                       "down-select"
#  +: "Shift-Option-Right Arrow"     # Extend text selection to the end of the current word, then to the end of the following word if pressed again (*)
\bind "A-Right"                      "word-right"
\bind "S-A-Right"                    "word-right-select"
#  +: "Shift-Option-Left Arrow"      # Extend text selection to the beginning of the current word, then to the beginning of the following word if pressed again (*)
\bind "A-Left"                       "word-left"
\bind "S-A-Left"                     "word-left-select"
#  +: "Shift-Option-Down Arrow"      # Extend text selection to the end of the current paragraph, then to the end of the following paragraph if pressed again (*)
\bind "A-Down"                       "paragraph-down"
\bind "S-A-Down"                     "paragraph-down-select"
\bind "S-M-A-Down"                   "inset-end-select"
#  +: "Shift-Option-Up Arrow"        # Extend text selection to the beginning of the current paragraph, then to the beginning of the following paragraph if pressed again (*)
\bind "A-Up"                         "paragraph-up"
\bind "S-A-Up"                       "paragraph-up-select"
\bind "S-M-A-Up"                     "inset-begin-select"

# ---------------------------------------------

# cmd + shift + M insert numbered formula
\bind "C-S-M"       "command-sequence math-display; math-number-toggle"

# cmd + shift + E = insert non-numbered formula
\bind "C-S-E"       "command-sequence math-display;"

# cmd + shift + n = nomenclature insert
\bind "C-S-N"       "nomencl-insert"

# cmd + shift + r = insert cross-reference
\bind "C-S-R"       "dialog-show-new-inset ref"

# cmd + shift + c = insert citation
\bind "C-S-C"       "dialog-show-new-inset citation"

# cmd + shift + L = insert label
\bind "C-S-L"       "label-insert"

# command-delete + r = delete row
\bind "C-Delete R"  "tabular-feature delete-row"

# command-delete + c = delete column
\bind "C-Delete C"  "tabular-feature delete-column"

# option-N = insert note
\bind "A-N"         "note-insert"

# option-C = insert comment
#\bind "M-S-C"         "comment-insert"

LyX 2.1.x


# This is my own bind file.
# Charles Reid.

# (cmd + , is show global lyx settings)
# cmd + shift + ,   show document settings
\bind "C-S-,"       "dialog-show document"


# Force LyX to exhibit normal mac behavior of 
# alt + left = left 1 word
# alt + right = right 1 word
# (this is necessary because setting this in LyX > Preferences > Control > "Use Mac-style for cursor moving between words" doesn't work)
\bind "A-Right"                      "word-right"
\bind "S-A-Right"                    "word-right-select"
\bind "A-Left"                       "word-left"
\bind "S-A-Left"                     "word-left-select"
\bind "A-Up"                         "paragraph-up"
\bind "S-A-Up"                       "paragraph-up-select"
\bind "A-Down"                       "paragraph-down"
\bind "S-A-Down"                     "paragraph-down-select"


# cmd + shift + M insert numbered formula
\bind "C-S-M"       "command-sequence math-display; math-number-toggle"

# cmd + shift + E = insert non-numbered formula
\bind "C-S-E"       "command-sequence math-display;"

# cmd + shift + n = nomenclature insert
\bind "C-S-N"       "nomencl-insert"

# cmd + shift + r = insert cross-reference
\bind "C-S-R"       "dialog-show-new-inset ref"

# cmd + shift + c = insert citation
\bind "C-S-C"       "dialog-show-new-inset citation"

# cmd + shift + L = insert label
\bind "C-S-L"       "label-insert"

# command-delete + r = delete row
\bind "C-Delete R"  "tabular-feature delete-row"

# command-delete + c = delete column
\bind "C-Delete C"  "tabular-feature delete-column"

# option-N = insert note
\bind "A-N"         "note-insert"

# option-C = insert comment
#\bind "M-S-C"         "comment-insert"

LyX 1.x

  # cmd + shift + M insert numbered formula
  \bind "C-S-M"       "command-sequence math-display; math-number-toggle"
  
  # cmd + shift + E = insert non-numbered formula
  \bind "C-S-E"       "command-sequence math-display;"
  
  # cmd + shift + n = nomenclature insert
  \bind "C-S-N"       "nomencl-insert"
  
  # cmd + shift + r = insert cross-reference
  \bind "C-S-R"       "dialog-show-new-inset ref"
  
  # cmd + shift + c = insert citation
  \bind "C-S-C"       "dialog-show-new-inset citation"
  
  # cmd + shift + L = insert label
  \bind "C-S-L"       "label-insert"
  
  # command-delete + r = delete row
  \bind "C-Delete R"  "tabular-feature delete-row"
  
  # command-delete + c = delete column
  \bind "C-Delete C"  "tabular-feature delete-column"
  
  # option-N = insert note
  \bind "M-N"         "note-insert"

  \bind "C-n"         "buffer-new"
  
  # reassigned... see above
  #\bind "C-S-N"          "buffer-new-template"

  
  \bind "C-M-b"           "font-boldsymbol"
  \bind "C-b"         "font-bold"
  \bind "C-e"         "font-emph"
  \bind "C-k"         "font-noun"     # 'k' for capitals
  \bind "C-u"         "font-underline"
  \bind "C-S-P"           "font-typewriter"       # 'P' for program *****
  \bind "C-m"         "math-mode"

Problems with Bind File in LyX 2.0

When I initially switched to LyX 2.0, I ran into problems with my bind file and with all of my shortcuts no longer working. The reason was, in LyX 2.0, the bind files have changed "C" to mean "Command", "M" to mean "Control", and "A" to mean "Alt/Meta/Option".

This change seems illogical to me, but once you change all your "M"s to "A"s, everything should work as expected.

Layouts vs. Classes

Using Latex Classes from Lyx

Nomenclature

LyX Layouts

Layouts are specific to LyX! They are not a LaTeX thing, they are a LyX thing. So, if you see something like file.layout, it is specifically for LyX.

The layout file will instruct LyX as to how to format and display everything. It will control things like fonts, sizes, lines, headers, footers, etc etc etc. Layout files are almost NEVER provided by journals, because journals expect people to use LaTeX - not LyX!

LaTeX Classes

Class files are for any LaTeX document. They do the same thing as a LyX layout file, except they do it for a LaTeX file. So, the class file controls things like fonts, sizes, lines, etc. for the LaTeX document. Class files are almost ALWAYS provided by journals, because journals expect people to use LaTeX when writing journal articles.

Umm..... what?

While this difference is superficially pretty arbitrary, and undocumented in LyX, it is a result of the fact that LyX speaks a "different language" than LaTeX. The way you tell LyX to "make the title bold" is different from the way you tell LaTeX to "make the title bold."

There is still the possibility to use one as the other! But it only works one way: you must have a LaTeX class that you want to use as a LyX layout (sorry folks, but using a LyX layout as a LaTeX class is not do-able, you have to convert it by hand or search for an associated LaTeX class somewhere on the internet: try here).


Using a LaTeX Class from LyX

In order to use a LaTeX class from LyX, you must do the following:

1. Install the LaTeX class file so that you can use it from LaTeX (this step is completely independent of LyX) by doing the following:

a) Find your local or system-wide LaTeX data directory. This may be in any number of places, but the local LaTeX data directory is most likely at $HOME/Library/texmf/tex/latex, and the global LaTeX data directory is most likely /usr/share/texmf/tex/latex. However, it can be in another place: for example, I use the TeXLive TeX distribution, and mine is located at /usr/local/texlive/2009/texmf/tex/latex. The texhash command knows where the global LaTeX directory is, so if you can't find the LaTeX data directory, try running the command texhash --verbose (you will probably have to run this command as root). This will tell you what directories contain the TeX databases. (Look at TeX documentation for an explanation of what that means).

(Also note that your distribution will probably come with a bunch of classes already, but they will be in some directory like /usr/share/texmf-dist/tex/latex or /usr/local/texlive/2009/texmf-dist/tex/latex/...)

On Mac OS X 10.8 (Mountain Lion), I had to run the command:

$ mkdir -p ~/Library/texmf/tex/latex/lyx

to make a directory for Latex class files that could be used from LyX.

b) Let's say your class file is named classfile.cls. You will want to make a directory called classfile in the LaTeX data directory that you found in part (a).

c) Finally, run the texhash command (you will probably have to run this command as root). This will add the new class file to TeX's (and, in turn, LaTeX's) internal list of class files that are installed on the system.

2. Create a layout file that will be associated with this class file. (This is necessary, since you can't use a class file from LyX directly... stupid, I know...) Fortunately it is pretty easy to do.

Find the basis class for your new class. For example, the LaTeX class amcsiggraph.cls is a descendant of article.cls. So in order to create a layout file that will allow you to use amcsiggraph.cls, you can use article.layout. You'll tell amcsiggraph layout to just use the article layout. Create a file acmsiggraph.layout in your layouts directory (the layouts directory is in your LyX data directory, see above). It should look something like this:

#% Do not delete the line below; configure depends on this      
#  \DeclareLaTeXClass[acmsiggraph]{ACM SigGraph}

# Read the definitions from article.layout
Input article.layout

See? That wasn't so bad.

3. Open LyX and click LyX > Reconfigure. This reconfigure command automatically generates a list of LyX layouts and their associated definition files (the .layout files), which are then used when you change the Document's settings to be this or that layout/class. Once LyX is done reconfiguring, it will give you a popup message that says you have to restart it. Restart it.

4. Create a new document, and click Document > Settings. Look for your new class in the drop-down list of layouts/classes.

IF this did not work for you... (it did not work for me)... you can re-do step (1a) as follows:

1. a) Click Tools > Tex Information. This will give you a list of all of the class and layout files that LyX was able to find using the built-in search function in TeX. Sometimes this built-in search function in TeX does NOT index the local or system-wide LaTeX data directory, so this window allows you to see what directories it DOES index. In my case, only the distribution-specific classes in /usr/local/texlive/2009/texmf-dist/tex/latex/ and the local classes (specifically for LyX) in $HOME/Library/texmf/latex/lyx were being indexed. Don't ask me why this happens; TeX is a complicated beast.

Repeat the above procedure, but using one of the directories that is definitely listed in the TeX Info window.


Using a LaTeX Class from LyX (Alternate Method, Updated Aug 2014)

Step 1: Install LaTeX Class

First, install your Latex class file (.cls) in a place where LyX can find it. I put mine in ~/Library/texmf/tex/latex/lyx.

Now run the texhash command to update your TeX database.

Step 2: Install LyX Layout

Install your LaTeX layout file in the LyX application data folder, located in ~/Library/Application Data/LyX-2.0/layouts.

Now open LyX and pick LyX > Reconfigure from the menu bar.

Now you can close LyX.

Step 3: Use LyX Layout

Now you should be able to use your LyX layout. Create a new document, and pick Document > Settings, and look for your new document class in the drop-down menu.


Using a LaTeX Class from LyX (Updated June 2018)

Step 1: Install LaTeX Class

Install the latex class file (.cls) in a place lyx can find the class file. Using homebrew-installed Latex, this was TEXDIR="/usr/local/texlive/2017/texmf-dist/tex/latex". I ran an mkdir -p $TEXDIR/lyx and put the class file in $TEXDIR/lyx.

Next, run texhash to update the TeX database.

Step 2: Install LyX Layout

Install your LaTeX layout file in the LyX application data folder, which is now in ~/Library/Application Support/LyX-2.2/layouts

Now open LyX and pick Tools > Reconfigure from the menu bar.

Now you can close LyX.

Step 3: Use LyX Layout

Now you should be able to use your LyX layout. Create a new document, and pick Document > Settings, and look for your new document class in the drop-down menu.

Creating LyX Layouts

Steve Litt's Sure Fire, No Fail Way to Create Lyx Layouts

Additionally, brief instructions can be found here: ICSE Technical Reports: Author Guide

Using External Latex Packages

Main article for LaTeX package installation is here: LaTeX

Article illustrating how to install/use a 3rd party package is here: Cancel Package

For the most part, using external LaTeX packages is straightforward. While LyX does not provide preview functionality for commands that are not built into LyX, they will work fine once the document is compiled. See Cancel Package#Using Cancel Package in LyX for more information and an example.

Errors

Document Class Unavailable

When I first installed LyX on Snow Leopard (Mac OS X 10.6), I saw some error messages like this:

I even saw this error message when I opened the built-in LyX documentation! The reason was (duh...) I hadn't installed a TeX system. I used MacTeX (http://www.tug.org/mactex/), and once I installed it everything worked fine.

References

  • LaTeX - information about installing and using LaTeX on your system (LyX requires a TeX system, and the LaTeX page contains information about installing a TeX system and getting it all set up)
  • LyX wiki: http://wiki.lyx.org/
    • I don't think this wiki is very good. It's poorly organized, it has provided me with incorrect information on more than one occasion, and it scatters information, making it difficult to find what I'm looking for. This is part of the reason I collect my LyX-related information and procedures on this page, rather than contributing to the LyX wiki.