Ceci est une ancienne révision du document !
In my last article, I explained Zim Wiki’s ability to be a shortcut for creating LaTeX documents, or at least creating text that can be easily imported into a LaTeX document. Importing text created in another program is not as straightforward as we may think. One issue is the way LaTeX handles characters such as ampersand, quotation marks and dollar signs. Cutting and pasting from a text editor or web page straight into a LaTeX editor can cause some strange characters to appear in your PDF file if your text includes symbols to which LaTeX takes exception. This creates a lot of grunt work that can be eliminated with applications that are configured to handle the exceptions and deal with them for you.
Two programs available in your Ubuntu repositories are Pandoc and Writer2Latex. You may install them via Synaptic or the command-line. If you are composing LaTeX documents on the Raspberry Pi, please be aware that Writer2Latex will add 106 MB of files to your disk. This may or may not be a problem, depending on the size of your SD card.
Pandoc
I am impressed with what Pandoc will do, especially with HTML files. Pandoc processed an HTML file that was mostly a table and did it quite well. I did have to edit my .tex file, though. First I had to add “\usepackage{longtable}” to my preamble, and I had to set my page margins with “\usepackage[left=0.50cm, right=0.50cm, top=1.00cm, bottom=1.00cm]{geometry}”.
In this conversion of an HTML table, Pandoc placed some code into the document that my LaTeX editor did not like. We see them in the form of the nasty error messages that pop up during the compile and view PDF stage. There are two things you can do: • Search on Google for the error and you may find a solution. Often this can be as easy as adding another line or two to your preamble. • Comment out the offending line of code with a “%” at the beginning of the line.
Pandoc is a command-line application but it is user-friendly. An example of a basic command is:
pandoc -s -o filename.tex filename.odt
filename.tex is what the resulting LaTeX file will be; filename.odt is the original file. (use the appropriate extension for your file.)
More information can be found at the Pandoc website: http://pandoc.org/
As good as Pandoc is, it has its limitations, as far as I know, concerning files from word processors. For example, Pandoc did not translate a very small simple table I made in an .odt file. This is surprising when I consider the great job Pandoc did on an HTML file that was mostly in a table format. This is where Writer2LaTeX comes in.
Writer2LaTeX
The website http://writer2latex.sourceforge.net/ has all the information about what the program can handle, and you may want to consult it before committing to use it for a large project. But it looks like it can convert anything we can create in an .odt document. If your original has been created in Microsoft Word, you will have to open the file in LibreOffice, save the file as an .odt document and then convert. The command-line input is just as user friendly as Pandoc:
w2l filename.odt filename.tex.
You may have noticed that the files are in the reverse order of the command you would use for Pandoc. You type in the name of the input file first and then the output tex file. I have tried it on an .odt file with a table in it and it worked like a charm. Moreover, Writer2LaTeX can handle some fairly complex .odt documents.
The manual for writer2latex is a whopping eighty-four pages long. There is lots to sink your teeth into, and it’s well worth the time to take a look at it so that you have an idea of what can be done.
You will also find information on these other applications: Writer2BibTeX, Writer2xhtml and Calc2xhtml.
The good news is that when you want to bring data into LaTeX from other sources, you have some very good tools at your disposal to make life easier. And the help you need is just a command line entry way.
Resources: Writer2LaTeX: http://writer2latex.sourceforge.net/
Pandoc: http://pandoc.org/