From charlesreid1

Line 134: Line 134:


= Layouts vs. Classes =
= Layouts vs. Classes =
[[Using Latex Classes from Lyx]]


== Nomenclature ==
== Nomenclature ==

Revision as of 20:44, 21 June 2013

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.

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 here.

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"

LyX 2.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-M-Right"                    "word-right-select"
\bind "L-Right"                      "word-left"
\bind "S-L-Right"                    "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"

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 is really stupid, 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 somewhat stupid and confusing, in addition to being COMPLETELY unclear from ANY webpage provided by 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.

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.