Computational Economics

computational tools for economists

Archive for the ‘LyX’ Category

Beginner Intro to TeX/LaTeX/LyX – How to set it up in Windows 7/8.1

leave a comment »

One way to easily install LaTeX and the editor LyX in Windows:

  1. Install MiKTeX. Run the update wizard to get the latest updates.
  2. Add your favorite document classes (e.g., Elsevier journal articles) to the path C:\Users\AppData\Roaming\MiKTeX\2.9\tex. [AppData does not appear in my pc because it’s hidden. Check by launching Windows Explorer then click on the View menu on the ribbon, now tick ‘Hidden items’.].
  3. Rehash by running texhash, or /miktex/bin/texhash.exe (on Windows this may be in C:\Programs).
  4. Install LyX. Click Tools > Reconfigure, and restart it.

Written by Jingjing Wang

04/26/2015 at 12:13 am

Posted in LyX

convert latex to rtf (doc, odt)

leave a comment »

Download latex2rtf: http://latex2rtf.sourceforge.net/

1. run LaTex first to get .aux file

2. run latex2rtf to get rtf and open it in Word

Note:

Many templates’ commands cannot be recognized. latex2rtf default set: \documentclass{article}. Delete \begin{article} and \end{article} in the template if there is errors during compiling.

Written by Jingjing Wang

07/02/2013 at 12:28 pm

Posted in LyX

Insert matlab code into LaTex

leave a comment »

  1. Download “M-code LaTeX Package” from Mathworks webpage
  2. Copy mcode.style to the folder C:\Program Files\MiKTeX 2.9\tex\latex\xcolor.
  3. Add the following in the preamble:\usepackage{listings}
    \usepackage{xcolor}
    \usepackage{textcomp}
    \usepackage[numbered,framed]{mcode}

In LyX, insert a TeX code box.

Insert m-code inline: \mcode{for i=1:3, disp(‘cool’); end;}

Insert m-code blocks: (% it’s a mess when copy and paste. prefer the 3rd approach)

\begin{lstlisting}
% Plot expected state and policy path
a = [a; c(:)’];
r = a’;
\end{lstlisting}

Insert a  m-code file:

\lstinputlisting[firstline=110, lastline=117]{/weed.m}

Written by Jingjing Wang

10/23/2012 at 11:14 am

Posted in LyX

Break long formulas in a cell of “cases environment”

leave a comment »

\begin{split}

…..\\

….

\end{split}

Insert the formula between the two commands.  Wherever you want to break the line, insert ‘\\’ (without the quotes)

Written by Jingjing Wang

05/04/2012 at 4:43 pm

Posted in LyX

dvipdfm vs. ps2pdf vs. pdflatex

leave a comment »

If a figure is pdf file, use psflatex (zooming does not affect the figure quality)

If a figure is eps file, any compiling route works.

Written by Jingjing Wang

04/11/2012 at 1:03 am

Posted in LyX

Adding .cls file to Lyx in Windows 7

leave a comment »

Reference: http://www.paulkiddie.com

This assumes version 2.9 of Miktex and version 2.0 of Lyx. If you are using an earlier or later versions, replace with the correct version numbers where I’ve used them.

  1. Get a copy of the class file, and copy it into a folder with the same name into C:\Users\\AppData\Roaming\MiKTeX\2.8\tex. So, for eethesis.cls, you should have a folder called eethesis within C:\Users\\AppData\Roaming\MiKTeX\2.8\tex. [AppData does not appear in my pc… Search for “AppData” and find the folder]
  2. Create a new file and paste the following into it:
    #% Do not delete the line below; configure depends on this
    # \DeclareLaTeXClass[xxx]{article (xxx)}
    # Input general definitions
    Input stdclass.inc

    replacing xxx with the class name (without the .cls extension). In my case, xxx is eethesis, and the code above becomes:

    #% Do not delete the line below; configure depends on this
    # \DeclareLaTeXClass[eethesis]{article (eethesis)}
    # Input general definitions
    Input stdclass.inc

    Thanks goes out to http://wastedmonkeys.com/2007/09/27/adding-a-new-class-in-lyx-windows for this.

  3. Save this file to C:\Program Files\LyX16\Resources\layouts, naming it eethesis.layout.
  4. In a command prompt (type cmd in start menu), type texhash. What you will now see it doing is iterating through several folders for new classes, one of which (C:\Users\AppData\Roaming\MiKTeX\2.8\) is where we copied the eethesis.cls class file into.
  5. Within Lyx, hit Tools > Reconfigure, then restart Lyx.
  6. Open a document and click Document > Settings. Click on ‘Document Class’, expand the drop down menu and you should see ‘article (xxx)’ is visible, and usable, (like below) within the drop down menu.

UCR Thesis Templates in Lyx

1) Copy and paste these into the Preamble

default page size – letter: 8.5in [1.5+6+1]*11in [1.5+8.5+1]

\textwidth = 6.00in
\textheight = 8.50in
\topmargin = 0.75in

2) I get an error when using \thebibliography: \newblock undefined.

Check the following in ucr.cls. Move it to the beginning of the bibliography section.
\def\newblock{\hskip .11em plus .33em minus .07em}

3)I got a LaTeX Error when using \subfig: No counter ‘subfigure@save’ defined.

Delete \usepackage{subfigure} in the Preamble

4) Bibliography/Table/Figure Caption is double-spacing

Add  ssp and dsp ( into a Tex Code box) before and after the BibTex Generated Bib box. Note that ssp and dsp have been defined in ucr.cls.

\ssp
BibTex Generated Bib
\dsp

5) Generate bookmarks in the PDF file

Document→Settings→PDF properties: check the boxes under Hyperlinks and Bookmarks dialog

6) Bibliography and Appendix do not appear in the table of contents (TOC)

use the package tocbibind from CTAN, i.e. add \usepackage{tocbibind} to the Preamble

7) Add additional entries to TOC

The following LaTeX command: \addcontentsline{toc}{chapter}{APPENDIX}  will add ‘APPENDIX’ to TOC and refer to the page where you have inserted this command. So this line should be added as ERT to the “page” of the document that you want to appear listed in the table of contents. This can also be used to include unnumbered sections to the TOC. Just insert the line immediately below the section header.

8) Table/Figure caption left-justified and bold

add \usepackage[nooneline, font={bf}]{caption} to the Preamble

9) Footnote spacing

space between footnotes: \setlength{\footnotesep}{2mm}
space between the text body and the footnotes: \setlength{\skip\footins}{1cm}

10) How to stop equation auto numbering in TeX code?

\begin{equation*} … \end{equation*}

11) How to modify Tex code from Mathematica so that it fits the thesis document class?

copy and paste into Notepad, replace \begin{doublespace} and \pmb with blank, replace \end{doublespace} with \par\vspace{5mm}. Break long lines in Mathematica before generating Tex code. In Mathematica, do not write comments in equations.

reading this link for inserting child document: http://stackoverflow.com/questions/5310409/how-to-add-a-large-code-appendix-in-latex-lyx

Method I use: save the code in a plain text file. create a Tex code box, Insert –> file –> Plain Text…


[http://www.sethi.org/utils/mynotes/public_notes/latex_notes]

Got the template from Kara; also available online at: http://www.math.ucr.edu/~jason/latextemplate/

  • Copy the following files to C:\Program Files\MiKTeX\tex\latex\ucr
    • sw20uctd.sty, thmsupp.tex, ucr.cls, uct10.clo, uct11.clo, uct12.clo
  • Next run MikTex ’s Settings and then Refresh FNDB
  • Create the following layout file, ucr.layout, in C:\Program Files\LyX16\Resources\layouts:

      #% Do not delete the line below; configure depends on this
      # \DeclareLaTeXClass[ucr]{article (ucr)}
      # Input general definitions
      Input stdclass.inc
    
      # Input lyx algorithm definitions (only if you've installed the algorithm package for Lyx from: http://bgu.chez-alice.fr/)
      Input algorithm.inc
  • Finally, run Tools → Reconfigure in Lyx
  • Next, Import the file uctest.tex into Lyx
    • Remove the Title and Author and, instead, add all the lines from \title to \maketitle into an ERT (a Tex Code box) since the \maketitle command Lyx inserts right after Title or Author causes a premature compilation error where it says \maketitle was not def ’ed; solution was as per here
    • Also, had to add \setlength\headsep{-0.5in} to the Latex Preamble in order to ensure the top margin isn ’t too large, as per: http://www.math.ucr.edu/~jason/latextemplate/
    • Also, had to change textheight to \textheight = 8.50in in the Latex Preamble from 8.25in
    • Had to comment out \newtheorem{algorithm}[theorem]{Algorithm} in the Latex Preamble, as well, in order to avoid errors when I include algorithms in the paper (since I add the algorithm style msyelf)
    • Finally, Kara wanted me to change to a darker font so I added \usepackage{palatino} to the Latex Preamble, as per http://www.image.ufl.edu/help/latex/fonts.shtml

Written by Jingjing Wang

11/29/2011 at 11:38 pm

Posted in LyX

Add space between the lines in multiline formulas

leave a comment »

In LATEX additional line space is specified as optional argument of the new line command. This is not yet possible in LYX33, therefore the whole formula must be inserted in TEX-mode. To add in our example space, the command \\[3mm] is inserted at the end of the first line.

1. select the part you’re interested, View -> View Source, copy the TeX code

2. go to .lyx, Insert -> Tex code (Ctrl+L), paste the code into the redbox, and add \\[3mm] at the end of the first line

 

To set the line separation for all lines in a formula, the length \jot is changed.

1. load the LATEX-package calc in LATEX-preamble with the line

\usepackage{calc}

2. insert the command
\setlength{\jot}{3mm+3pt}

in TEX-mode before the formula

Written by Jingjing Wang

10/30/2011 at 7:50 pm

Posted in LyX

Break long formulas in a parenthesis in LyX

with one comment

Lyx has an “Insert -> Math -> AMS multiline environment” control, but does not work in the middle of a parenthesis.

How to break lines in the middle of a parenthesis?

In AMS multiline environment,

\left[\right.

(line break here) \left.\right]

Do not use Alt+M to get a parenthesis. Follow the way above. Close with ‘\right.’ before line-break and reopen with ‘\left.’

\left[\left[\right.\right.

(line break here) \left.\left.\right]\right]

This can lead to parentheses of different size. Size them yourself using ‘\big(‘, ‘\Big(‘, ‘\Bigg(‘, etc. or use \vphantom.

Written by Jingjing Wang

10/30/2011 at 6:40 pm

Posted in LyX

Pasting data into .lyx / Text wrapping in table in LyX

leave a comment »

Pasting data into .lyx

1. open your xls file

2. Select the requisite number of columns and rows

3. Come back to your lyx document

4. Insert a table which has at least the selected number of rows and columns

5. Go to the cell on your lyx table where you want the top left corner of the
section to be placed.

6. select either Edit -> Paste Special -> Plain Text or Edit -> Paste Special -> Plain Text, Join Lines

Text wrapping in table in LyX

LaTeX’s algorithms for formatting tables have a few shortcomings. One is that it will not automatically wrap text in cells, even if it overruns the width of the page. For columns that you know will contain a certain amount of text, then it is recommended that you use the p attribute and specify the desired width of the column (although it may take some trial-and-error to get the result you want). Use the m attribute to have the lines aligned toward the middle of the box and the b attribute to align along the bottom of the box.

LyX: right click in a cell -> more… -> setting… -> Table Settings (column settings, row settings, etc.)

Written by Jingjing Wang

10/29/2011 at 12:33 am

Posted in LyX

Generate EPS file for LaTeX/LyX and reduce the size if too big

leave a comment »

Reference

Wikibooks: LaTeX/Importing Graphics

CS professor at NCSU: Tools and Tips for Writing Papers

The only format you can include while compiling with latex is Encapsulated PostScript (EPS).

How to convert Microsoft Office Documents to EPS file?

Method 1

use the default printer in Windows 7: Metafile to EPS Converter

print –> current page/selection –> get the PRN file

use GSview (Ghostscript)

file –> PS to EPS –> get the EPS file with graph fitting to the bounding box

Method 2

use OpenOffice to open the file you have

file –> export –> get the EPS file

Conclusion

use Microsoft Office + Metafile to EPS Converter +  GSview

use OpenOffice directly

How to crop an image in EPS format?

use a text editor (e.g. Vim, Crimson) to open the file

The beginning of EPS usually looks like

%!PS-Adobe-3.0 EPSF-3.0
%%BoundingBox: 0 0 555 735

(0,0) left bottom; (555 735) right top

change the four number to crop the image. You can check it in GSview.

What if EPS images make the file too big?

use GSview (Ghostscript)

file -> convert -> [personal taste. 3D EPS from Mathematica: png16+Resolution300. chart from Calc: png256+Resolution300]

cut png/JPG? ? use IrfanView+PlugIns

edit -> Auto crop borders

Written by Jingjing Wang

10/24/2011 at 9:17 pm

Posted in LyX