You are currently browsing the archives for the LaTeX category.

## Converting LaTeX documents to Word

I was disappointed to discover that IEEE Pervasive Magazine need my article as a Microsoft Word document because they don’t know how to handle LaTeX files. I don’t understand how a serious scientific society or a professional editor can not be able to handle plain text files, especially since the final typesetting probably takes place in another piece of software.

Fortunately, I found the GrindEQ LaTeX-to-Word converter, a sort of plugin for Word which allows you to open .tex files. It adds some menus to the Word ribbons (toolbars at the top of the page) and makes Word able to open .tex files from the usual File -> Open menu. When you open a LaTeX file, GrindEQ will remind you that you can only run it 10 times before having to register. It may also encourage you to install Ghostscript if you work with EPS files. Remember to set the LaTeX encoding to UTF-8 or whatever you use if you want accented characters to appear correctly.

I was very impressed with the formatting. Almost everything was correct. It’s not the prettiest Word document and it doesn’t seem to use the Word styles (eg., header 1, header 2, paragraph) but the equations and figures were mostly correct. Here are the errors that I noticed.

• In one equation, the norm symbols (double bars) had been replaced by a ‘P’ character in special font.
• A numbered list which was programmed to start from a value greater than 1 didn’t.
• The title was missing and the document started with a blank page.
• Some figures which were laid out in LaTeX using the \subfloat command were displayed in sequence with their subcaptions. I created a table to hold these figures.
• At a few places in the text, the letters ieeetr appeared because I was using the bibunits package with that particular style of bibliography.
• I used bibunits to create two bibliographies. LaTeX numbers them both starting from 1, but in Word they were all in one continuous sequence. This is not a problem because the reference numbers are consistent between the text and the bibliography.

## Bibtex errors about using both author and editor fields

In my list of references, there is a paper which is a chapter in a book. It seemed obvious that this should be a @INBOOK in Bibtex. However this entry type won’t let you specify both author and editor. You will see the Bibtex message Warning--can't use both author and editor fields in fischer11slam.

In this particular case, the paper isn’t a chapter in a book by a single author, but it’s a chapter in a collection of articles by different authors. The @INCOLLECTION entry type is the correct one to use.

The @BOOK type will also not allow both author and editor. I find this less understandable but perhaps in the case of a real book, the editor takes on a more understated role.

## Breaking LaTeX enumerations but keeping the counter

I’m using a LaTeX enumeration to describe an algorithm. I want to break the enumeration into two parts with a brief sentence between them explaining that the second part is only executed under certain conditions. I would like the numbers on the second list to start where the first one stopped. Anders Sjöqvist has had the same problem and has explained how to achieve this.

\begin{enumerate}
\item First operation.
\item Second operation.
\newcounter{enumi_saved}
\setcounter{enumi_saved}{\value{enumi}}
\end{enumerate}
The following operations are only executed if a particular condition is true.
\begin{enumerate}
\setcounter{enumi}{\value{enumi_saved}}
\item Third operation (conditional).
\end{enumerate}


If there are several levels of enumerations, the counters enumii, enumiii… will also be defined.

## Saving space in LaTeX

Trying to resubmit a paper to a different conference and realising rather late that the new lncs format (Springer single column) makes the article many pages longer than the previous two column ACM format. Fortunately Tim Love at Cambridge University Engineering Department has put together a page of hints for reducing the length of a LaTeX article. Here are the ones I found most helpful.

• Include the a4 package to reduce the size of the margins, works even if the page size is already a4.
• Allow LaTeX to fit more figures, tables and text onto a single page by redefining the *fraction commands and *counter values.
• Using \centering inside figure environments instead of \begin{center}… This seems to reduce space around figures.
• Use the abbrv bibliography style which only uses initials for first names.
• Shorten the names of proceedings, e.g., Proc. of EWSN. The year is unnecessary since it usually has its own field. Some journals also have standard abbreviations.
• For the anonymous version use \author{} and \institute{} instead of commenting out those lines. This will avoid the document reading ‘No Author Given’ and ‘No Institute Given’.

## Correct bounding box in EPS figures

Epstool works best for me, as suggested by La Consigna: how to export correctly from Matlab and how to fix bounding boxes with epstool. I needed to manually edit one of my eps figures to increase the bounding box to avoid part of the right hand border of the plot from being clipped.

epstool --copy --bbox input.eps output.eps


This also works for me but seemed to cause some ugly aliasing on the text:

eps2eps ugly_figure.eps nice_figure.eps


which can be put into a loop like this

for file in original/*.eps; do eps2eps $file fixed/basename$file; done


Another technique is:

cat figure.eps | ps2eps > figure2.eps


Thanks to Stephan for this. He wrote his tip for OpenOffice figures but it also works for Matlab figures that have too much white space around them and that mess up LaTeX documents.

There is a shell script called epscrop. It’s available from CTAN as part of the figfrag package. It doesn’t work for me. I get it mixed up with pdfcrop that I’ve mentioned in another post and which does work.

## Breaking sentences into separate lines with Vim

I just read somewhere that when writing LaTeX documents it’s useful to have each sentence on a new line. My current document only has (double) line breaks between paragraphs. Here is how to use Vim to insert line breaks after each full stop.

In command mode press ‘:’ then enter s/\.\s\+/\.^M/. The ^M character represents a line break and must be inserted with CTRL-V Enter. Press enter to run the substitution on the current line. Add a percent character to run the substitution on the whole file: %s/\.\s\+/\.^M/.

Some more useful commands in a SunWorld article from 1997.

## Figures for publication

When producing camera ready versions of publications it seems best to create a Postscript file and then convert to PDF. Some printers (printing companies) require the Postscript files and it’s also the only way I’ve found to correctly embed all the fonts in the PDF.

In Matlab I’ve been using set(gcf, 'PaperPositionMode', 'auto'); print -depsc myfigure.eps; to create the eps file for including in LaTeX.

Run latex mypaper.tex to produce the dvi file.

Run dvips -Ppdf -G0 -tletter mypaper.dvi to produce the PS.

Run ps2pdf -dPDFSETTINGS=/printer -dCompatibilityLevel=1.3 -dMaxSubsetPct=100 -dSubsetFonts=true -dEmbedAllFonts=true -sPAPERSIZE=letter mypaper.ps to produce the final PDF file. Use pdffonts mypaper.pdf to check that all fonts are correctly embedded.

Replace letter with a4 in the dvips and ps2pdf commands if you’re publishing for Europe.