[Tex/LaTex] How to interpret message “Invalid UTF-8 stream” when trying to convert a tex-file to a rtf-file using pandoc

pandoc

I want to convert a .tex file into something that is possible to open in MS Word (.doc, .docx, .rtf, …) by means of the pandoc command line software. A minimum .tex file is attached below. I use the following command in a standard command window when trying to convert :

pandoc -o MyFile.tex MyFile.rtf

This produces the following error message:
enter image description here

What does "Invalid UTF-8 stream" mean, and what can I do about it? I am using MikTeX 2.9 and TexWorks.

My latex file MyFile.tex is like this:

% !TeX program    = pdflatex
% !TeX encoding   = ISO-8859-1
% !TeX spellcheck = nb_NO

\documentclass[10pt,a4paper,twosided]{article}

\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsthm} 
\usepackage{amssymb}
%\usepackage[dvips]{graphicx}
\usepackage{graphicx}

%\usepackage[french,english]{babel}
\usepackage[english]{babel}
%\usepackage[latin1]{inputenc}

\usepackage[usenames,dvipsnames]{color}
\usepackage{subfigure}
\usepackage{natbib}
\usepackage{dcolumn}

\usepackage{bm}
\usepackage{url}

\usepackage{alltt}
\usepackage{xspace}
\usepackage{enumerate}
\usepackage{textcomp}
\usepackage{etoolbox}
\usepackage{longtable}
\usepackage{pdflscape} 
%\usepackage[absolute,showboxes]{textpos}
\usepackage[absolute]{textpos}

\usepackage{fancyhdr}
\usepackage{array}
\usepackage{tabularx}
\usepackage{xfrac}

\usepackage{fmtcount}
\usepackage{mfirstuc}
\usepackage[width=0.95\textwidth,font={bf,small}]{caption}[2011/08/06]

\usepackage{booktabs}
\usepackage[table]{xcolor}

\usepackage{tikz}
\usepackage{pgfplots}
  \pgfplotsset{compat=newest}
  \pgfplotsset{plot coordinates/math parser=false}

\usepackage{filecontents}
\usepackage[pagewise,displaymath,mathlines]{lineno}
\usepackage{layout}
\usepackage[margin=1in]{geometry}
\usepackage{changepage}
\usepackage{placeins}
\usepackage{paralist}
\usepackage{refcount}

\usepackage[pdftex]{hyperref}


\hypersetup{pdfauthor = Espen Donali}

\hypersetup{pdfdisplaydoctitle=true}
\hypersetup{bookmarks=true}
\hypersetup{pdfpagemode=UseOutlines}
\hypersetup{pdfpagelayout=TwoColumnRight}

\hypersetup{pdfmenubar=true}
\hypersetup{pdftoolbar=true}
\hypersetup{dvips}
\hypersetup{hyperfigures}
\hypersetup{pdfstartview=FitV}

\hypersetup{backref=page}
\hypersetup{pagebackref=true}

\hypersetup{colorlinks=true}
\hypersetup{allcolors=blue}
\hypersetup{linkcolor=blue}
\hypersetup{citecolor=blue}
\hypersetup{urlcolor=blue}
\hypersetup{anchorcolor=red}
\hypersetup{menucolor=red}
\hypersetup{runcolor=red}
\hypersetup{hyperfootnotes=true}



\begin{document}

my test of pandoc latex to word

\end{document}

enter code here

Best Answer

You have told your editor that the file is stored as latin1 encoding

% !TeX encoding   = ISO-8859-1

But pandoc thinks it is reading a UTF-8 encoded file so can not decode it. These encodings are the same for ascii letters but differ for anything else.

Pandoc may have an option to tell it the file encoding or if not, you should get your editor to save the file as utf-8.

Related Question