Archive

Archive for the ‘latex’ Category

LaTeX: strike through a text

February 17, 2014 Leave a comment

Problem
You want to have this effect in LaTeX.

Solution

\usepackage{soul}

You want to have \st{this effect} in \latex.
Categories: latex Tags:

Merge PDF files and start each on the right side (on an add page)

January 8, 2013 Leave a comment

Problem
I had several small PDF files that I wanted to print in one shot. With pdftk you can concatenate them easily but I wanted to see each document to start on an odd page, i.e. on the right side. How to do that?

Solution
A hackish solution is to use pdftk. Check the number of pages and if it’s odd, insert a blank page. Then merge ‘em all.

A better way is to leave the job for LaTeX:

\documentclass[a4paper]{article}
\usepackage{pdfpages}

\begin{document}

\includepdf[pages={-}, openright]{01.pdf}
\includepdf[pages={-}, openright]{02.pdf}
\includepdf[pages={-}, openright]{03.pdf}
%...

\end{document}

Compile the source with “pdflatex”. Warning! The part “pages={-}” means to insert the whole PDF, from start to end. If you forget that, it’ll insert just the 1st page of a PDF.

Tip from here and here.

minted – highlighted source code for LaTeX

March 4, 2012 Leave a comment

minted is a package that facilitates expressive syntax highlighting in LaTeX using the powerful Pygments library. The package also provides options to customize the highlighted source code output using fancyvrb.

PDF doc is here.

Example (minimal.tex):

\documentclass{article}
\usepackage{minted}    % import the package here
\begin{document}
\begin{minted}{c}
int main() {
    printf("hello, world");
    return 0;
}
\end{minted}
\end{document}

Compilation:

$ pdflatex -shell-escape minimal

Alternatives

  • \begin{verbatim} ... \end{verbatim}
  • \begin{lstlisting} ... \end{lstlisting}

Squeezing Space in LaTeX

February 18, 2012 Leave a comment

Problem
You have written a nice paper that is 17 pages long but the limit is 16 pages. You try to remove some parts of it but it’s still 16.5 pages long. What to do?

Solution
Squeeze that space! Add the following line to your LaTeX source:

\linespread{0.9}

The difference is unnoticable. Once your paper is accepted, you can correctly reduce its size to the limit.

Find more tricks here.

Reset footnote counter in LaTeX

December 28, 2011 Leave a comment

Problem
In our paper we have 3 authors and our LaTeX style uses footnotes to show their affiliations. Then, numbering footnotes in the text starts with 4. How to reset it back to 1?

Solution
After the list of authors, add this line:

\setcounter{footnote}{0}

More info here.

A little help for hyphenating words in LaTeX

September 28, 2011 Leave a comment

Problem
When working with LaTeX, sometimes I’m not sure if a word is correctly hyphenated by LaTeX so I’d like to verify that. As I’m not a native English speaker, it’d be nice to hear the correct pronunciation too.

Solution
I made a little script that addresses the two problems (available here). It’s part of my jabbapylib library. The script relies on dictionary.com.

LaTeX: using verbatim in footnote

September 7, 2011 Leave a comment

Problem
You want something like this:

\footnote{See \verb|http://www.google.com|.}

But LaTeX drops an error. Unfortunately verbatim is not allowed in footnotes.

Solution
But there is a workaround:

\footnote{See \texttt{http://www.google.com}.}

Tip found here.

Categories: latex Tags: , ,

Convert PDF to EPS

July 13, 2011 Leave a comment

Problem
I wanted to submit a paper but they required the LaTeX source too, including the images. They accepted EPS images but not PDF! WTF? All my images are in PDF format. How to convert them to EPS?

Solution

pdftops -eps file.pdf

This tip is from here.

Appendix
Here I had another difficulty: EPS images are not supported by pdflatex. Great! So I had to switch back to the old latex command…

Compilation with pdflatex:

#!/bin/bash

MAIN=main.tex

pdflatex $MAIN.tex
bibtex $MAIN
pdflatex $MAIN.tex
pdflatex $MAIN.tex

\rm *.aux *.blg *.dvi *.log *.bbl *.flg *.idx *.ind *.lof *.lot *.toc *.glo *.gls *.ilg 2>/dev/null

Compilation with latex:

#!/bin/bash

MAIN=main.tex

LATEX=latex

$LATEX $MAIN.tex
bibtex $MAIN
$LATEX $MAIN.tex
$LATEX $MAIN.tex
dvips $MAIN.dvi -o $MAIN.ps
ps2pdf $MAIN.ps

\rm $MAIN.ps *.aux *.blg *.dvi *.log *.bbl *.flg *.idx *.ind *.lof *.lot *.toc *.glo *.gls *.ilg 2>/dev/null
Categories: latex Tags: , , , ,

Replace accents for LaTeX

I have two simple scripts for LaTeX for working with special accented characters. They are made for Hungarian and French but they can be customized easily for other languages too.

replace_latex_accents.pl
This script allows you to write special Hungarian and French characters in a simple way (using the ISO-8859-1 (Latin-1) charset), then convert them to their LaTeX-equivalents.

Example: La'szlo' => L\'{a}szl\'{o}

replace_french_accents_to_latex.pl
This script converts a French accented text to LaTeX replacing the funny characters with their LaTeX equivalents.

Example: é => \'{e}

The scripts are available here.

Related stuff

Remove comments from a LaTeX file

June 13, 2011 Leave a comment

Problem
I had to remove all the comments from a LaTeX file.

Solution
LaTeX comments start with ‘%‘. It was enough to remove comments that start at the beginning of a line.

cat file.tex | grep -v ^%

(Yeah, I know, it’s two processes, but I prefer like this…)

Generalization
If your comments start with ‘#‘, use “cat file | grep -v ^#“.

Categories: bash, latex Tags: ,
Follow

Get every new post delivered to your Inbox.

Join 72 other followers