title: How it is possible to convert LaTeX document to Word (docx file) with all cross-references and labels for images and equations, tables by Pandoc?
body: <p>I have a tex-file obtained originally from RStudio with bookdown. The original set of Rmd-files were deleted by accident.<br />
  So I need to convert below minimized correct tex-file to Word (docx file extension):</p>
  <pre><code>% Options for packages loaded elsewhere
  \PassOptionsToPackage{unicode}{hyperref}
  \PassOptionsToPackage{hyphens}{url}
  %
  \documentclass[
  ]{article}
  \usepackage{amsmath,amssymb}
  \usepackage{lmodern}
  \usepackage{iftex}
  \ifPDFTeX
    \usepackage[T1]{fontenc}
    \usepackage[utf8]{inputenc}
    \usepackage{textcomp} % provide euro and other symbols
  \else % if luatex or xetex
    \usepackage{unicode-math}
    \defaultfontfeatures{Scale=MatchLowercase}
    \defaultfontfeatures[\rmfamily]{Ligatures=TeX,Scale=1}
  \fi
  % Use upquote if available, for straight quotes in verbatim environments
  \IfFileExists{upquote.sty}{\usepackage{upquote}}{}
  \IfFileExists{microtype.sty}{% use microtype if available
    \usepackage[]{microtype}
    \UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
  }{}
  \makeatletter
  \@ifundefined{KOMAClassName}{% if non-KOMA class
    \IfFileExists{parskip.sty}{%
      \usepackage{parskip}
    }{% else
      \setlength{\parindent}{0pt}
      \setlength{\parskip}{6pt plus 2pt minus 1pt}}
  }{% if KOMA class
    \KOMAoptions{parskip=half}}
  \makeatother
  \usepackage{xcolor}
  \IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available
  \IfFileExists{bookmark.sty}{\usepackage{bookmark}}{\usepackage{hyperref}}
  \hypersetup{
    pdftitle={Simple document},
    hidelinks,
    pdfcreator={LaTeX via pandoc}}
  \urlstyle{same} % disable monospaced font for URLs
  \usepackage[margin=1in]{geometry}
  \usepackage{longtable,booktabs,array}
  \usepackage{calc} % for calculating minipage widths
  % Correct order of tables after \paragraph or \subparagraph
  \usepackage{etoolbox}
  \makeatletter
  \patchcmd\longtable{\par}{\if@noskipsec\mbox{}\fi\par}{}{}
  \makeatother
  % Allow footnotes in longtable head/foot
  \IfFileExists{footnotehyper.sty}{\usepackage{footnotehyper}}{\usepackage{footnote}}
  \makesavenoteenv{longtable}
  \usepackage{graphicx}
  \makeatletter
  \def\maxwidth{\ifdim\Gin@nat@width&gt;\linewidth\linewidth\else\Gin@nat@width\fi}
  \def\maxheight{\ifdim\Gin@nat@height&gt;\textheight\textheight\else\Gin@nat@height\fi}
  \makeatother
  % Scale images if necessary, so that they will not overflow the page
  % margins by default, and it is still possible to overwrite the defaults
  % using explicit options in \includegraphics[width, height, ...]{}
  \setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio}
  % Set default figure placement to htbp
  \makeatletter
  \def\fps@figure{htbp}
  \makeatother
  \usepackage[normalem]{ulem}
  % Avoid problems with \sout in headers with hyperref
  \pdfstringdefDisableCommands{\renewcommand{\sout}{}}
  \setlength{\emergencystretch}{3em} % prevent overfull lines
  \providecommand{\tightlist}{%
    \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
  \setcounter{secnumdepth}{5}
  \ifLuaTeX
    \usepackage{selnolig}  % disable illegal ligatures
  \fi
  \usepackage[]{biblatex}
  \addbibresource{bibliography.bib}
  
  \title{Simple document}
  \author{}
  \date{\vspace{-2.5em}}
  
  \usepackage{amsthm}
  \newtheorem{theorem}{Theorem}[section]
  \newtheorem{lemma}{Lemma}[section]
  \newtheorem{corollary}{Corollary}[section]
  \newtheorem{proposition}{Proposition}[section]
  \newtheorem{conjecture}{Conjecture}[section]
  \theoremstyle{definition}
  \newtheorem{definition}{Definition}[section]
  \theoremstyle{definition}
  \newtheorem{example}{Example}[section]
  \theoremstyle{definition}
  \newtheorem{exercise}{Exercise}[section]
  \theoremstyle{remark}
  \newtheorem*{remark}{Remark}
  \newtheorem*{solution}{Solution}
  \begin{document}
  \maketitle
  
  {
  \setcounter{tocdepth}{2}
  \tableofcontents
  }
  \hypertarget{format}{%
  \section{Format}\label{format}}
  
  Read \ref{format} for details.
  
  Or read \protect\hyperlink{format}{format}.
  
  Formatting:
  
  \begin{itemize}
  \tightlist
  \item
    sup-script or power - x\textsuperscript{2} ;
  \item
    sub-script - y\textsubscript{3} ;
  \item
    strike through - \sout{strike through} ;
  \item
    term -- definition ;
  \item
    long term --- long definition .
  \end{itemize}
  
  Here comes \textbf{footnote} \footnote{Footnote text} with its contents.
  
  Image with caption, see \ref{fig:image}.
  
  \begin{figure}
  \centering
  \includegraphics{image.png}
  \caption{\label{fig:image} Image}
  \end{figure}
  
  Labeled table is below, see table \ref{tab:table}.
  
  \begin{longtable}[]{@{}ll@{}}
  \caption{\label{tab:table}\\
  My table}\tabularnewline
  \toprule
  \textbf{Col 1 header} &amp; \textbf{Col 2 header} \\
  \midrule
  \endfirsthead
  \endhead
  r1c1 &amp; r1c2 \\
  r2c1 &amp; r2c2 \\
  \bottomrule
  \end{longtable}
  
  Inline: \(a^2 + b^2 = c^2\).
  
  Block:
  
  \[ E = \frac{mc^2}{\sqrt{1-\frac{v^2}{c^2}}} \]
  
  Labeled, see \eqref{eq:eq}:
  
  \begin{equation}
  f\left(k\right) =\binom{n}{k} p^k\left(1-p\right)^{n k}
  \label{eq:eq}
  \end{equation}
  
  See LaTeX \autocite{latex} site for details.
  
  Code is below, see \ref{exm:code}:
  
  \begin{example}
  \protect\hypertarget{exm:code}{}{\label{exm:code} }Hello world
  \end{example}
  
  \begin{verbatim}
  int main(){
    return 0;
  }
  \end{verbatim}
  
  \hypertarget{references}{%
  \section*{References}\label{references}}
  \addcontentsline{toc}{section}{References}
  
  \printbibliography
  
  \end{document}
  </code></pre>
  <p>When I try to convert it to docx using pandoc (2.16.1 version) command below:</p>
  <p><code>pandoc simple.tex --to docx+native_numbering --output simple.docx --table-of-contents --toc-depth 5 --number-sections --citeproc --verbose --csl ieee.csl</code></p>
  <p>(In the above command ieee.csl was downloaded <a href="https://www.zotero.org/styles/ieee" rel="nofollow noreferrer">from Zotero</a>).</p>
  <p>I get</p>
  <p><a href="https://i.stack.imgur.com/oUGYW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/oUGYW.png" alt="Pandoc Latex to docx" /></a></p>
  <p>and I see many strange things:</p>
  <ul>
  <li><code>[fig:image]</code> along with Figure with number;</li>
  <li><code>[tab:table]</code> along with Table with number;</li>
  <li><code>[eq:eq]</code> instead of equation number;</li>
  <li><code>[exm:code]</code> instead of example number.</li>
  </ul>
  <p>Is it possible to replace (or suppress them for Figure and Table) above strange <code>[…]</code> fields by correct numbers and links using Pandoc to get correct docx output?</p>