Ping Services

Thursday, November 24, 2011

Tips to get you started with Lyx part 2


I wrote Tips to get you started with Lyx a year ago. I've always wanted to do a follow-up article and so here it is. For those who don't know about Lyx or LaTeX, you should check out my previous articles here and here.



Tip 8: Skip page numbering on the title page.

Step 1:
Insert ERT (Evil Red Text (Plain LaTeX)) by pressing CTRL+L

Step 2:
Within the ERT, type in \thispagestyle{empty}

Tip 9: Set your header and footer.
I will show you how to set a custom left, right and center header and footer.

Step 1:
Go to the LaTeX Preamble (Document » Settings) and paste the following:

\lhead{}
\chead{}
\rhead{}
\lfoot{}
\cfoot{}
\rfoot{}
\date{}


Step 2:
Under Document Settings, go to Page Layout and set the heading style to fancy.

Step 3:
Now you can enter custom headers and footers within the curly brackets.



If you would like to get the headers and footers on the title page as well, I would recommend not defining text as a Title but rather increasing the size of your title while keeping the text type standard.


Tip 10: How to solve the csname font error on Windows.


\csname\endcsname=psyr at 10.0pt not loadable: Metric (TFM) file not found

If you keep getting this error, I pity you. Not because of the problem as it is easily solved but because of the fact that you are running Windows.

Step 1:
Go to the Start Menu » All Programs » MikTex » Maintainance (admin) » Package manager (admin)


Step 2:
Install the package "Symbol"


The symbol package allows you to export Mathematical symbols, ridding you of this pesky error.

Important: For the next 2 tips, it is good practice to leave out symbols before exporting a table as it could cause errors, leading to an incomplete export. It's is preferable to add symbols within Lyx itself.

Tip 11: Exporting tables from Excel to Lyx.
I had previously shown you how to copy tables from Open/Libreoffice Calc to Lyx as it may be preferable for some to perform their calculations there and then later copy and paste the table. Here are instructions to do the same with Microsoft Excel:

Step 1: Get excel2latex
Excel2latex is a plugin for Microsoft office that will let you convert a table to LaTeX. It can be downloaded here.

Step 2:
Open the downloaded file with Microsoft Excel. You might get an error like the one below but check the name of the macro and then click on enable macros.


Step 3:


After selecting a table go to Add ins and click on convert table to latex.

Step 4: 

An output window will pop up, allowing you to save the code by pressing Save to file.


Step 5: 
Go to File » Import » Plain LaTeX on Lyx and import the table.

Tip 12: Exporting tables from Gnumeric to Lyx
Unlike Open/Libreoffice, the spreadsheet program Gnumeric has the ability to export a table to LaTeX by default. Here's what you need to do:

Step 1:
Create a new sheet and paste your table there if there are multiple tables on the same sheet.



Step 2:
Go to File » Save As and choose LaTeX 2e (Table Fragment).


Step 3:
Once saved, you can go to File » Import » Plain LaTeX on Lyx and import the table.

Tip 13: Add programming code
One of the great things about LaTeX is the ability to add programming code very easily. What's awesome is that your code will be syntax-highlighted with line numbers so that it looks like a snippet from a text editor. Here you can see an example of how some Ada code has been syntax-highlighted.


Programming code can be entered into Lyx by doing the following:

Step 1:
In the preamble of the document (accessible by going to Document » Settings » LaTeX Preamble) add "\usepackage{listings}"

Step 2:  
Copy and paste the following lines to your Preamble

\lstset{ %
language=Octave,                % the language of the code
basicstyle=\footnotesize,       % the size of the fonts
numbers=left,                   % position line-numbers
numberstyle=\footnotesize,      % the size of the line-number fonts
stepnumber=1,                   % If it's 1, each line will be numbered
numbersep=5pt,                  % distance between line-numbers and code
backgroundcolor=\color{white},  % choose background color. You must add \usepackage{color}
showspaces=false,               % show spaces adding particular underscores
showstringspaces=false,         % underline spaces within strings
showtabs=false,                 % show tabs within strings adding particular underscores
frame=single,                   % adds a frame around the code
tabsize=2,                      % sets default tabsize to 2 spaces
captionpos=b,                   % sets the caption-position to bottom
breaklines=true,                % sets automatic line breaking
breakatwhitespace=false,        % sets if automatic breaks should only happen at whitespace
title=\lstname,                 % show the filename of files included with \lstinputlisting;
escapeinside={\%*}{*)},         % if you want to add a comment within your code
morekeywords={*,...}            % if you want to add more keywords to the set
}


You have to enter the language of your code on the second line. The \listings package supports the following languages:

ABAP IDL PL/I
ACSL inform Plasm
Ada Java POV
Algol JVMIS Prolog
Ant ksh Promela
Assembler2 Lisp Python
Awk Logo R
bash make Reduce
Basic2 Mathematica1 Rexx
C Matlab RSL
C++ Mercury Ruby
Caml MetaPost S
Clean Miranda SAS
Cobol Mizar Scilab
Comal ML sh
csh Modelica3 SHELXL
Delphi Modula-2 Simula
Eiffel MuPAD SQL
Elan NASTRAN tcl
erlang Oberon-2 TeX
Euphoria OCL VBScript
Fortran Octave Verilog
GCL Oz VHDL
Gnuplot Pascal VRM
Haskell Perl XML
HTML PHP XSLT

Step 4: Typing the code within Lyx
You can type code within Lyx by going to Insert » Program Listing

Step 5: Importing the code from a file
If you prefer to, you can also import the code that you wish to add to your document by specifying a source file. Remember to keep the source file in the same folder as your Lyx file.

Then press CTRL+L and type
\lstinputlisting{filename.extension}
\usepackage{textcomp}

\usepackage{xcolor}

That would be all. I hope that you found this article useful. I am also writing a review of the latest OpenSUSE release. Hopefully, I will be able to finish it by next week.

All articles The Review Meter How Software is reviewed

Links:
[1] Tips to get you started with Lyx part 1
[2] Lyx : The best way to write your documents
[3] Latex and Lyx, Tips and tricks
[4] Excel2latex

No comments:

Post a Comment