# LaTeX tips

(Difference between revisions)
 Revision as of 21:22, 23 April 2009 (view source)Chloe (Talk | contribs) (→Converting from other formats)← Older edit Latest revision as of 21:39, 12 December 2018 (view source)Elliot (Talk | contribs) m (→Tips and Tricks) (43 intermediate revisions by 9 users not shown) Line 5: Line 5: ==Recommendations for downloads== ==Recommendations for downloads== − * Best Windows LaTeX compiler [http://miktex.org/ Miktex] + * Standard Windows LaTeX compiler [http://miktex.org/ Miktex] − * Best Windows editor [http://www.toolscenter.org/ TeXnicCenter] + * Standard Windows editor [http://www.toolscenter.org/ TeXnicCenter] − * Best Mac editor [http://www.uoregon.edu/~koch/texshop/ TeXShop] + * Standard Mac editor [http://www.uoregon.edu/~koch/texshop/ TeXShop] − * Best Mac compiler [http://www.tug.org/mactex/ MacTeX] + * Standard Mac compiler [http://www.tug.org/mactex/ MacTeX] + * General purpose editor [https://www.sublimetext.com/3/ SublimeText3] which combined with the package LaTeXTools and the PDF viewer [https://skim-app.sourceforge.io/ Skim] (Mac) or [https://www.sumatrapdfreader.org/free-pdf-reader.html/ Sumatra] (Windows) can be used as a lightweight TeX editor * A Linux Integrated LaTeX Enivronment [http://kile.sourceforge.net/ Kile] * A Linux Integrated LaTeX Enivronment [http://kile.sourceforge.net/ Kile] * For any Linux/Unix system, simply use your favourite Unix editor to type the mylatex.tex file. [http://www.rpi.edu/dept/arc/web/docs/QuickStudies/quick20/quick20.html Here] is a basic list of Unix commands. To check your spellings, you can say * For any Linux/Unix system, simply use your favourite Unix editor to type the mylatex.tex file. [http://www.rpi.edu/dept/arc/web/docs/QuickStudies/quick20/quick20.html Here] is a basic list of Unix commands. To check your spellings, you can say ispell mylatex.tex (.tex extension may be omitted) ispell mylatex.tex (.tex extension may be omitted) + A better program for spell-checking on linux is Aspell. + Replace ispell above with aspell . − in the shell. + Emacs also provides a great environment for LaTeX. While using Emacs, install [http://www.gnu.org/software/auctex/ AucTeX] for best results. + * Using (La)TeX with Gmail [http://alexeev.org/gmailtex.html GmailTeX]. Remember to use the F8 key to compose/read received messages and change the text formatting from "Rich Text" to "Plain Text" while composing messages. ==General setup== ==General setup== * Compiling the LaTeX using pdfTeX allows the creation of pdf files as the final product and the inclusion of graphics created as pdf files from some other source. For many people this is more convenient than using postscript files which may be the default for LaTeX compilers and editors. pdfTeX works nicely with images produced as pdf files (see [[R/General Information on Plotting]]). * Compiling the LaTeX using pdfTeX allows the creation of pdf files as the final product and the inclusion of graphics created as pdf files from some other source. For many people this is more convenient than using postscript files which may be the default for LaTeX compilers and editors. pdfTeX works nicely with images produced as pdf files (see [[R/General Information on Plotting]]). + + ==Tips and Tricks== + + * [https://www.math.hmc.edu/computing/support/tex/latex-hints.pdf/ General tips and tricks] + * Chapter 3 of this [https://www.math.hmc.edu/seniorthesis/guidelines/handbook/hmc-math-thesis-handbook.pdf/ math thesis handbook] contains tips for TeXing a large file such as a thesis + * The LaTeX preamble is basically all the commands between your \documentclass{class} call and your \begin{document} call. Preamble's are often either largely empty, resulting in a boring document, or very obtuse. Pre-constructed preamble files provide a useful way to define the same commands and load the same packages in multiple files, thereby allowing you to make all your documents the same kind of pretty. An example of a preamble is given [https://github.com/cokasaki/latex-tools/ here]. To load a preamble file simple place at the beginning of your document: + \documentclass{class} + \input{mypreamble.tex} + \begin{document} + + * When using Sublime Text (and numerous other text editors) [http://docs.sublimetext.info/en/latest/extensibility/snippets.html/ snippet] files increase efficiency. Snippets basically allow you to type part of a command, press TAB, and have the whole command automagically appear. For example, an alternative to having just one preamble file might be a snippet that triggers on "doc" or "pres." You type just a few characters, hit TAB and suddenly your file is populated with the basic framework you need to make a document or presentation. Some examples of snippets that are useful in LaTeX are given [https://github.com/cokasaki/latex-snippets here]. A handy way to sync your snippets from computer to computer is to make a folder my_snippets in Dropbox, and place a [https://www.howtogeek.com/297721/how-to-create-and-use-symbolic-links-aka-symlinks-on-a-mac/ symlink] to this folder in your Sublime Text Packages/User folder + * LaTeX uses something called a texmf tree to search through files when compiling. If you have common files that you want it to always be able to access, no matter where your document is located, place them in your texmf tree. For example, this would be a convenient place for preamble files. A handy way to sync your texmf tree from computer to computer is to make a folder texmf in Dropbox, and place a [https://www.howtogeek.com/297721/how-to-create-and-use-symbolic-links-aka-symlinks-on-a-mac/ symlink] to this folder in your Sublime Text Packages/User folder. Alternatively you can [https://tex.stackexchange.com/questions/145196/create-a-local-texmf-tree-in-mactex/ add its location] to your TEXMFHOME variable. On a Mac this can be accomplished from Terminal + sudo tlmgr conf texmf TEXMFHOME ":" + + ==Bibliography Management== + Typically we have a .bib file in the same + directory as the .tex file. + At end of your file add the following commands + + + \bibliographystyle{plain} + \bibliography{bibfile} + + + Then run + + latex myfile + + + on your tex file + and + + bibtex myfile + + twice. + Repeat + latex and your file should have your references. + + If you want to include references from your database + that are not cited in the + .tex file add + + \nocite{*} + + above the two lines. + + For chapter by chapter references, + add + + \usepackage{chapterbib} + + to your preamble. + Presumably you have a root file + with + + \include{} + + for each of your chapters. Then run + latex + on your root file, + but run + bibtex on each of your included files. + + Sometimes you need to modify the bibliography style file, say to meet the formatting requirements for a journal. [http://chenfuture.wordpress.com/2007/09/24/diy-your-bibtex-style-file/ Here] is a nice set of instructions. ==Converting from other formats== ==Converting from other formats== Line 23: Line 91: For equations, the only software that QERMunists have found to be truly great is GrindEQ's [http://www.grindeq.com/index.php?p=word2latex Word2LaTeX]. Unfortunately, that one costs $129, but they have a "fully functional evaluation/download version", so as long as you fully embrace LaTeX after converting your files, then you could get by with just the free trial. For equations, the only software that QERMunists have found to be truly great is GrindEQ's [http://www.grindeq.com/index.php?p=word2latex Word2LaTeX]. Unfortunately, that one costs$129, but they have a "fully functional evaluation/download version", so as long as you fully embrace LaTeX after converting your files, then you could get by with just the free trial. − MathType (unfortunately no longer [http://www.washington.edu/uware/mathtype free], $57), will nicely convert individual equations written in Equation Editor or MathType to LaTeX. Within MathType, use the menu for Preferences > Translators, and select "Translation to other language" and pick the default, "TeX -- LaTeX 2.09 and later". Now highlight any equation in the MathType window and paste into a text file. The pasted text should appear as text in LaTeX syntax. + MathType (unfortunately no longer free!, [http://www.washington.edu/uware/mathtype$57 or 30-day trial] that might be enough to move all the way to LaTeX), will nicely convert individual equations written in Equation Editor or MathType to LaTeX. Within MathType, use the menu for Preferences > Translators, and select "Translation to other language" and pick the default, "TeX -- LaTeX 2.09 and later". Now highlight any equation in the MathType window and paste into a text file. The pasted text should appear as text in LaTeX syntax. Anyone have any success converting using Open Office, or even seeing MathType-produced equations in Open Office? Anyone have any success converting using Open Office, or even seeing MathType-produced equations in Open Office? ==Converting to other formats== ==Converting to other formats== + ===Converting to Word=== + Sometimes your adviser won't want to receive a PDF, wanting the convenient track-changes functionality in Word. The [http://www.pdftoword.com/#Nitro PDF to Word converter] works pretty well, and is free to use online or you can download a 14-day trial. It converts your equations to images and, while the fonts may be different, the result accompanied by the original PDF should satisfy your adviser. Unfortunately, after the 14-day trial the full product is over $100, so I've moved to the official Adobe ExportPDF, which you can subscribe to for a year for$20... it seems to do a better job on text but messes up PDF figures in unpredictable ways. − On Linux or any Unix-like system, in the terminal just type + I've also used [http://www.zamzar.com/#Nitro Zamzar], an onine file converter where you upload your file, select the output you'd like, and give it your email address, and the site emails you a link to download your converted document. You can choose to convert a pdf to .doc, .docx, and many others. Figures within your pdf do not come through very well, but the equations usually do, and it's certainly a way to solicit edits and feedback from an advisor or collaborator who wants to use Word. + + ===latex2rtf=== + [http://latex2rtf.sourceforge.net/ latex2rtf] converts .tex documents to .rtf, which can be opened in [http://www.openoffice.org/ Open Office] or Word and saved as a .doc. Get it [http://sourceforge.net/project/showfiles.php?group_id=22654 here] (windows) or your favorite package manager (linux/mac).  Usage is as simple as latex2rtf myfile latex2rtf myfile − where myfile has extension .tex. The output is a .rtf file, which can be opened in [http://www.openoffice.org/ Open Office] and saved as a .doc. It didn't seem to do the equations, though graphics worked out quite nicely. I will eventually test how it handles bibliographies and add that here. + where myfile has extension .tex and has already been compiled. There are switches to control how equations are handled (see the [http://latex2rtf.sourceforge.net/latex2rtf_1_9_19.html#Using-LaTeX2RTF documentation] for more details), and some examples are -M3 (convert both inline and displayed equations to RTF), -M12 (convert both inline and displayed equations to bitmaps), and -M32 (insert the raw latex equation delimited by <<: and :>>). If you choose to insert the raw latex equation and you have MathType, you can convert equations to MathType equations by cutting/pasting the latex into the MathType window, or with MathType 6.5 for windows, highlight the latex equation in Word and click the TeX toggle command on the toolbar. Latex2rtf supports bibliographies. − Does anyone have good ideas on converting from tex to others on Windows or anything else? Do any of the popular tex front ends (texnic center, for example) have options for this? + '''latex2rtf for dummies (aka eileen) on a ''Mac''''' + + * If you know how to install things with Unix commands, you are not a dummy. + * Otherwise, (and this doesn't necessarily mean you're a dummy), get a package installer (i-installer or FinkCommander); [http://latex2rtf.sourceforge.net/latex2rtf_1_9_19.html#Macintosh make your choice here]. + * Use these to find latex2rtf.  i-installer was already on my computer, and filled in the blanks as far as many of the prerequisite packages. e.g. I think I needed ImageMagick and FreeType2 to start. + * Also find and install package netpbm.  I found this with FinkCommander, but not with i-installer.  This will make more of your error messages disappear. + * Next use Terminal, available already on your Mac.  It's very similar to the windows command prompt.  Type: + latex mypaper + bibtex mypaper # if you use bibtex + latex2rtf mypaper + These are the same commands as above, more details available [http://en.wikibooks.org/wiki/LaTeX/Export_To_Other_Formats#Convert_to_RTF here]. + * Terminal details I don't want to look up again and you may find helpful: + ** "pwd" returns current directory. + ** "cd /Users/yourname/YourFolder/" changes the current directory to the folder YourFolder on your hard drive. + ** "cd /Volumes/Cruzer/MyFolder/" changes the current directory to the folder MyFolder on a thumb drive that calls itself Cruzer. + ** To run latex2rtf on a .tex file, use the "cd" command to put yourself in the right directory, then follow the steps above. + ** Error messages will be shown in Terminal, and generally correspond either to programs or packages not installed, or to LaTeX functions not recognized.  Check the documentation link above to see if your referenced function has any hope of being found by latex2rtf or if it will simply be ignored. + ** To find if there are hidden files on your computer, e.g. in /usr/local/bin/, which may be referenced by some of the source code, type "open -a finder /usr/local/bin/".  I ran into a few error messages that led me to believe I was missing files either in this folder or in /usr/bin/.  Use i-installer or FinkCommander to find any more necessary packages. + *Finally, when you have run latex2rtf and you want to see the results, make sure to open your newly created .rtf file in Word.  None of the bitmaps or rtf math conversions will show up if you let the default program (TextEdit on my computer) open the file. + + ===GrindEQ=== + [http://www.grindeq.com/index.php?p=latex2word GrindEQ LaTeX-to-Word] is a windows-only product that converts .tex to .doc.  It costs €49 but the evaluation version comes with 10 launches. + + ===Adobe Acrobat Pro=== + Acrobat Pro will export .pdf files to Word.  It does alright with the text portions, but the equation conversion is pretty awful. Unfortunately, some of the converted documents hang Word, YMMV. + + ===Open Office=== + [http://www.openoffice.org/ Open Office 3] can import .pdf files and then save them as Word files. Equations look OK, but seem to be a collection of images, rather than any editable equation format. + + == Compatibility with R == + + Sweave is a great way to embed R output in LaTeX. {{Pdf |SweaveSeminaR.pdf | Here}}  is a GREAT example, and perhaps everything you need to start. + + [http://cran.r-project.org/web/packages/xtable/index.html xtable] is a nice R function (thanks [[User:Eli|EliG]]) to produce latex style tables in R ==Useful Links== ==Useful Links== Line 42: Line 148: * Good reference on figures, captions, positioning and other headaches: [ftp://ftp.tex.ac.uk/tex-archive/info/epslatex.pdf Importing Graphics in LaTeX] * Good reference on figures, captions, positioning and other headaches: [ftp://ftp.tex.ac.uk/tex-archive/info/epslatex.pdf Importing Graphics in LaTeX] + + * Every symbol you could ever imagine: [http://www.math.utoronto.ca/mathit/symbols-letter.pdf The Comprehensive LaTeX Symbol List] + + ==Word Count== + You can count words after compiling to pdf with the following command. More details [http://markelikalderon.com/2006/11/04/latex-word-count-and-textmate/ here]. + + ps2ascii mydocument.pdf | wc -w ==Additional Pages== ==Additional Pages==

## Latest revision as of 21:39, 12 December 2018

This will be a repository of tips for using LaTeX. To add a tip, just create a link below, for example: Separating the Red Sea and save the page. The link will be red. Just click on the red link and you will automatically be editing the page. Nothing like a blank canvas to share your hard-gleaned wisdom!

## Contents

• Standard Windows LaTeX compiler Miktex
• Standard Windows editor TeXnicCenter
• Standard Mac editor TeXShop
• Standard Mac compiler MacTeX
• General purpose editor SublimeText3 which combined with the package LaTeXTools and the PDF viewer Skim (Mac) or Sumatra (Windows) can be used as a lightweight TeX editor
• A Linux Integrated LaTeX Enivronment Kile
• For any Linux/Unix system, simply use your favourite Unix editor to type the mylatex.tex file. Here is a basic list of Unix commands. To check your spellings, you can say

ispell mylatex.tex (.tex extension may be omitted) A better program for spell-checking on linux is Aspell. Replace ispell above with aspell .

Emacs also provides a great environment for LaTeX. While using Emacs, install AucTeX for best results.

• Using (La)TeX with Gmail GmailTeX. Remember to use the F8 key to compose/read received messages and change the text formatting from "Rich Text" to "Plain Text" while composing messages.

## General setup

• Compiling the LaTeX using pdfTeX allows the creation of pdf files as the final product and the inclusion of graphics created as pdf files from some other source. For many people this is more convenient than using postscript files which may be the default for LaTeX compilers and editors. pdfTeX works nicely with images produced as pdf files (see R/General Information on Plotting).

## Tips and Tricks

• General tips and tricks
• Chapter 3 of this math thesis handbook contains tips for TeXing a large file such as a thesis
• The LaTeX preamble is basically all the commands between your \documentclass{class} call and your \begin{document} call. Preamble's are often either largely empty, resulting in a boring document, or very obtuse. Pre-constructed preamble files provide a useful way to define the same commands and load the same packages in multiple files, thereby allowing you to make all your documents the same kind of pretty. An example of a preamble is given here. To load a preamble file simple place at the beginning of your document:
 \documentclass{class}
\input{mypreamble.tex}
\begin{document}

• When using Sublime Text (and numerous other text editors) snippet files increase efficiency. Snippets basically allow you to type part of a command, press TAB, and have the whole command automagically appear. For example, an alternative to having just one preamble file might be a snippet that triggers on "doc" or "pres." You type just a few characters, hit TAB and suddenly your file is populated with the basic framework you need to make a document or presentation. Some examples of snippets that are useful in LaTeX are given here. A handy way to sync your snippets from computer to computer is to make a folder my_snippets in Dropbox, and place a symlink to this folder in your Sublime Text Packages/User folder
• LaTeX uses something called a texmf tree to search through files when compiling. If you have common files that you want it to always be able to access, no matter where your document is located, place them in your texmf tree. For example, this would be a convenient place for preamble files. A handy way to sync your texmf tree from computer to computer is to make a folder texmf in Dropbox, and place a symlink to this folder in your Sublime Text Packages/User folder. Alternatively you can add its location to your TEXMFHOME variable. On a Mac this can be accomplished from Terminal
 sudo tlmgr conf texmf TEXMFHOME "<insert old texmf tree path here>:<insert new texmf tree path here>"


## Bibliography Management

Typically we have a .bib file in the same directory as the .tex file. At end of your file add the following commands

\bibliographystyle{plain} \bibliography{bibfile}

Then run latex myfile

on your tex file and bibtex myfile twice. Repeat latex and your file should have your references.

If you want to include references from your database that are not cited in the .tex file add \nocite{*} above the two lines.

For chapter by chapter references, add \usepackage{chapterbib} to your preamble. Presumably you have a root file with \include{} for each of your chapters. Then run latex on your root file, but run bibtex on each of your included files.

Sometimes you need to modify the bibliography style file, say to meet the formatting requirements for a journal. Here is a nice set of instructions.

## Converting from other formats

There are a variety of tools for converting to LaTeX from other formats, many of which are described here. For equations, the only software that QERMunists have found to be truly great is GrindEQ's Word2LaTeX. Unfortunately, that one costs $129, but they have a "fully functional evaluation/download version", so as long as you fully embrace LaTeX after converting your files, then you could get by with just the free trial. MathType (unfortunately no longer free!,$57 or 30-day trial that might be enough to move all the way to LaTeX), will nicely convert individual equations written in Equation Editor or MathType to LaTeX. Within MathType, use the menu for Preferences > Translators, and select "Translation to other language" and pick the default, "TeX -- LaTeX 2.09 and later". Now highlight any equation in the MathType window and paste into a text file. The pasted text should appear as text in LaTeX syntax.

Anyone have any success converting using Open Office, or even seeing MathType-produced equations in Open Office?

## Converting to other formats

### Converting to Word

Sometimes your adviser won't want to receive a PDF, wanting the convenient track-changes functionality in Word. The PDF to Word converter works pretty well, and is free to use online or you can download a 14-day trial. It converts your equations to images and, while the fonts may be different, the result accompanied by the original PDF should satisfy your adviser. Unfortunately, after the 14-day trial the full product is over $100, so I've moved to the official Adobe ExportPDF, which you can subscribe to for a year for$20... it seems to do a better job on text but messes up PDF figures in unpredictable ways.

### latex2rtf

latex2rtf converts .tex documents to .rtf, which can be opened in Open Office or Word and saved as a .doc. Get it here (windows) or your favorite package manager (linux/mac). Usage is as simple as latex2rtf myfile where myfile has extension .tex and has already been compiled. There are switches to control how equations are handled (see the documentation for more details), and some examples are -M3 (convert both inline and displayed equations to RTF), -M12 (convert both inline and displayed equations to bitmaps), and -M32 (insert the raw latex equation delimited by <<: and :>>). If you choose to insert the raw latex equation and you have MathType, you can convert equations to MathType equations by cutting/pasting the latex into the MathType window, or with MathType 6.5 for windows, highlight the latex equation in Word and click the TeX toggle command on the toolbar. Latex2rtf supports bibliographies.

latex2rtf for dummies (aka eileen) on a Mac

• If you know how to install things with Unix commands, you are not a dummy.
• Otherwise, (and this doesn't necessarily mean you're a dummy), get a package installer (i-installer or FinkCommander); make your choice here.
• Use these to find latex2rtf. i-installer was already on my computer, and filled in the blanks as far as many of the prerequisite packages. e.g. I think I needed ImageMagick and FreeType2 to start.
• Also find and install package netpbm. I found this with FinkCommander, but not with i-installer. This will make more of your error messages disappear.
• Next use Terminal, available already on your Mac. It's very similar to the windows command prompt. Type:
latex mypaper
bibtex mypaper # if you use bibtex
latex2rtf mypaper


These are the same commands as above, more details available here.

• Terminal details I don't want to look up again and you may find helpful:
• "pwd" returns current directory.
• "cd /Users/yourname/YourFolder/" changes the current directory to the folder YourFolder on your hard drive.
• "cd /Volumes/Cruzer/MyFolder/" changes the current directory to the folder MyFolder on a thumb drive that calls itself Cruzer.
• To run latex2rtf on a .tex file, use the "cd" command to put yourself in the right directory, then follow the steps above.
• Error messages will be shown in Terminal, and generally correspond either to programs or packages not installed, or to LaTeX functions not recognized. Check the documentation link above to see if your referenced function has any hope of being found by latex2rtf or if it will simply be ignored.
• To find if there are hidden files on your computer, e.g. in /usr/local/bin/, which may be referenced by some of the source code, type "open -a finder /usr/local/bin/". I ran into a few error messages that led me to believe I was missing files either in this folder or in /usr/bin/. Use i-installer or FinkCommander to find any more necessary packages.
• Finally, when you have run latex2rtf and you want to see the results, make sure to open your newly created .rtf file in Word. None of the bitmaps or rtf math conversions will show up if you let the default program (TextEdit on my computer) open the file.

### GrindEQ

GrindEQ LaTeX-to-Word is a windows-only product that converts .tex to .doc. It costs €49 but the evaluation version comes with 10 launches.

Acrobat Pro will export .pdf files to Word. It does alright with the text portions, but the equation conversion is pretty awful. Unfortunately, some of the converted documents hang Word, YMMV.

### Open Office

Open Office 3 can import .pdf files and then save them as Word files. Equations look OK, but seem to be a collection of images, rather than any editable equation format.

## Compatibility with R

Sweave is a great way to embed R output in LaTeX. Here is a GREAT example, and perhaps everything you need to start.

xtable is a nice R function (thanks EliG) to produce latex style tables in R

• Great resource to get started and have questions answered: LaTeX WikiBook
• A quick cheat sheet of all the things you forget. Cheat Sheet

## Word Count

You can count words after compiling to pdf with the following command. More details here.

ps2ascii mydocument.pdf | wc -w