I’m trying to convert a report from LaTeX to OpenDocument (.odt) or Office Open XML (.docx) formats. But the programs give errors and stop, so in the end neither formats are written.

First I use Pandoc:

pandoc -f latex -t docx -o file.docx file.tex

But then it outputs the message:

Error at "file.tex" (line 124, column 20):
expecting \end{figure}

I have revised the code and there is the corresponding \par, so I tried to erase these tags, but it isn’t compiled. It says

unexpected {

Again I revised it, but the centerings are written as \begin{centering} and \par\end{centering} and all are paired, so I can't locate the mismatch

  • Option 2: mk4ht Used the following command

    mk4ht oolatex file.tex

It starts compiling, shows a list of libraries and files, but it stops and outputs:

! Emergency stop.
<inserted text>
l.25 \babel@aux{spanish}{}

Output written on file.dvi (53 pages, 15708 bytes).
Transcript written on file.log.
--- error --- failed to execute command

And the dvi file can't be opened.

At starting, Pandoc was saying that the file isn't in UTF-8, and manually change the encoding. The TeX file is a large one, so perhaps isn’t for loading here, and I don't know what parts could be relevant to post.

So how can it be tweaked to get something converted to these formats?

MWE (this file is a portion of the main TeX file)


 breaklinks=true,pdfborder={0 0 1},backref=false,colorlinks=true]
 pdfsubject={opamp, feedback},
 pdfkeywords={opamp, feedback},
 linkcolor=black, citecolor=black, urlcolor=blue, filecolor=blue, pdfpagelayout=OneColumn, pdfnewwindow=true, pdfstartview=XYZ, plainpages=false}

  \pagenumbering{arabic} }



\title{\textsf{\large{} Title}}
\author{\textsf{Bowie}\thanks{\textsf{\large{}\protect\href{mailto:[email protected]}{[email protected]}}}}


\section{\textsf{\large{}El amplificador operacional ideal}}

\subsection{\textsf{El amplificador operacional}}


\textsf{\large{}Some text}{\large\par}

\textsf{\large{}More text }{\large\par}

\textsf{\large{}and more text}{\large\par}

\textsf{\large{}Again text}{\large\par}

\textsf{\large{}Bla... }{\large\par}


text added}{\large\par}
%here starts the problems
%the ouput is
%Error at "file.tex" (line 107, column 20):
%expecting \end{figure}
\textsf{\large{}\caption{Caption of the figure}



The source is compiled with LaTeX and a PDF file is generated, but reviewing the log I have found the next information (the parts I think are relevant):

 restricted \write18 enabled.
 %&-line parsing enabled.
... no UTF-8 mapping file for font encoding PU
Package geometry Warning: The marginal notes overrun the paper.
     Add 11.32088pt and more to the right margin.
Output written on Intro.pdf (45 pages, 731901 bytes).
PDF statistics:
 565 PDF objects out of 1000 (max. 8388607)

And amid the compilations says something about missing $s, } unwanted or no $, and absent glyphs (this is in the terminal and I can’t save it, and it isn’t in the logs).

I have tested with other TeX files and the conversion went well.


I have reviewed the figures and I have the following code (of the part of the figure)

\textsf{\large{}\caption{Caption for the figure.}

The centering and center are in pairs. So I don’t know why at the MWE is different, but even in this way the output is the same.


I have revamped the code and modified the figure sets, and now the document is well converted to .odt and .docx. The only thing is the figures lost their numeration and alignment.

  • 4
    Before compiling your document with pandoc, maybe first assure that you can compile it with LaTeX. I get a number of errors, first about the encoding (I guess \usepackage[latin9]{inputenc} may not be your best choice if you use utf-8), but also you have troubles in your figure: there is a \end{centering} but no \begin{centering}... and centering is not an environment. Also, I'm not sure to see why you need that many \par. For instance the \par right after the caption break the latex compilation.
    – tobiasBora
    Sep 21, 2021 at 20:50
  • 3
    Then, once it compiles, you can try to see what disturbs pandoc. For instance, pandoc asks for \textsf to be inside the caption and not outside (which does make sense). Fixing that seems to solve the problem for me. To fix your whole document, I guess you can use search&replace tools, or sed in linux.
    – tobiasBora
    Sep 21, 2021 at 20:54
  • 2
    @tobiasBora,Im going to make a revision on the source, I was advised that $\par$ need to be used to correctly align the figure environments. It indeed compiles on LaTex, but I wasn't aware of the warnings
    – avelardo
    Sep 21, 2021 at 21:37
  • 2
    centering is not an environment, use \centering I can not guess the intention of lines such as \textsf{\large{}} or {\large\par} you should delete all such lines. It is not surprising that pandoc can not convert this document, the latex markup is rather strange. \textsf{\large{}\includegraphics{pasted1}}{\large\par} shoule be \includegraphics\{pasted1} you can not apply font commands to an image. Sep 21, 2021 at 22:15
  • 7
    really it's surprisng that latex makes a pdf from this at all, only by lack of error checking, it is ompossible to even guess the intention of most of the lines here, it is certainly far from any normal latex markup. why is every line wrapped in \textsf for example??? Sep 21, 2021 at 22:20

4 Answers 4


Converting to ODT with make4ht

Today make4ht is the best tool for this purpose. Write your LaTeX file as usual, with the proviso that you avoid exotic syntax and remove all packages that are not strictly necessary just to process the file (i.e., to run latex without errors). Forget about fancy formatting; keep it simple.

Then you do as follows:

latexmk -pdf file
make4ht -f odt file

You can use LibreOffice to save the resulting ODT file in DOCX format. (You can actually do it on the command line in some setups.)

Alternative (better for HTML): lwarp

Another option is lwarp, which works wonderfully to generate HTML (see its documentation for how to do it, it's pretty simple). After opening the html file in a browser you can copy from the browser window and paste into LibreOffice and the results are passable. The unusual handling of footnotes in this setup were a dealbreaker for me, though.

But it's harder in Spanish

Even once I rewrote your sample document in correct and reasonable LaTeX code, I did run into problems because using Spanish in babel interacts badly with a lot of other packages.

  • I found that adding the es-sloppy option cleared up most of the problems by disabling some of the "bonus" features enabled in this Babel configuration. But still, when converting with make4ht, the table of contents included unwanted junk code written into the ODT output.
  • Removing the contents lists solved the problems, and perhaps you can do without them in the ODT output. (Libreoffice does have its own ways of generating contents lists.)

A separate question about babel Spanish and make4ht is warranted.

The following document I think captures most of what you were trying to do, and both compiles to PDF and converts to ODT with no problems.

\documentclass[letterpaper, 12pt]{article} 

% Because seems like you want a sans-serif typeface

% Please note that the last option is necessary for conversion to work in
% Spanish


\author{Bowie\thanks{\href{mailto:[email protected]}{[email protected]}}}

% I can't get the contents lists to work in Spanish with make4ht
\section{El amplificador operacional ideal}
\subsection{El amplificador operacional}
Algunas palabras.\footnote{Una nota.}
Más palabras.
Y más.
Añado algo más (vease figura \ref{fig:pasted1}).
%    \includegraphics{pasted1} % I don't have the image to include
    \caption{Descripción de la imágen}
  • I have tried this way and it tells me the same error eveb when I have depurated it.
    – avelardo
    Sep 22, 2021 at 2:37
  • 1
    @corie See my edits. These show more standard coding practices for what I think you are trying to write, and also how to deal with converting a Spanish document. Sep 22, 2021 at 14:00
  • Thanks for your valuable information, and support. Indeed, there are trouble with the spanish babel pack. Sometimes I have to write in it, and usually some warnings and disabled features appears. I will look for the question. Thanks a lot again, you are very kind.
    – avelardo
    Sep 22, 2021 at 14:50

The easiest way, I think, to convert a tex, PDF-file, to word or libreoffice format (.docx) is to use this online convertor https://pdf2docx.com


I successfully LyX as a tool to this end. Keep the formatting of LaTeX as simple as possible. Launch LyX and import the file. Then export as "Open Document (pandoc)". Then, use LibreOffice to convert to doc if you like.


MS Word does a pretty good of importing PDF documents and converting them to .docx. It will not do well with advanced graphics and fancy headers though. You might save some time by simply opening the PDF output of LaTex in MS Word, and saving it as .docx.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .