Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am (losing my mind) trying to convert a TeX file to a Word with latex2rtf. The body translates well, but the tables don't. I use a lot of cross-references and out like to maintain them.

My solution is to push the tables to the end of the document. I'd like to go further and suppress table output, but keep the cross-references. This would be one less step in my conversion process because I wouldn't have to cut the bad tables out of the Word document before appending back the good tables made outside of LaTeX.

I tried the comment environment from the verbatim package, but this doesn't work because the cross-references don't survive. Is this possible? Or should I just accept that I can't script everything? Thanks!

\documentclass[12pt]{article}
\usepackage{verbatim}

\begin{document}
I would like to reference Table \ref{tab:1}, which is pushed to the end of 
the paper with a {\tt clearpage} and commented out because it doesn't convert 
correctly in {\tt latex2rtf} and I will find a solution outside of \LaTeX.

\clearpage
\begin{comment}
\begin{table}
  \centering
  \begin{tabular}{ l c r }
    1 & 2 & 3 \\
    4 & 5 & 6 \\
    7 & 8 & 9 \\
  \end{tabular}
  \caption{This table is my white whale.}
  \label{tab:1}
\end{table}
\end{comment}

\end{document}

Edit: FWIW, my main problem with the tables in latex2rtf seems to be ifmmode macros, which cause frequent crashes.

share|improve this question
add comment

2 Answers

up vote 4 down vote accepted

The following code allows you to leave the tables as-is in your document (and not push them to the end), yet obtain correct references. Well, for the labels at least. Page references, as expected, would be useless/lost, since the actual table is never set. However, you mention that this will be processed outside of the LaTeX environment.

enter image description here

\documentclass{article}
\usepackage{environ}% http://ctan.org/pkg/environ
\makeatletter
\providecommand{\env@table@save@env}{}%
\providecommand{\env@table@process}{}%
\RenewEnviron{table}[1][]
{{\def\label##1{\gdef\recall@label{\label{##1}}}% Redefine \label to store label
 \renewcommand{\caption}[2][]{}% Remove caption capability
 \setbox1=\hbox{\BODY}}% Execute environment body and store it in a box
 \refstepcounter{table}\recall@label% Recall label
}
\makeatother

\begin{document}
I would like to reference Table~\ref{tab:1}, which is pushed to the end of 
the paper with a \verb|clearpage| and commented out because it doesn't convert 
correctly in \verb|latex2rtf| and I will find a solution outside of \LaTeX.

\begin{table}
  \centering
  \begin{tabular}{ l c r }
    1 & 2 & 3 \\
    4 & 5 & 6 \\
    7 & 8 & 9 \\
  \end{tabular}
  \caption{This table is my white whale.}
  \label{tab:1}
\end{table}

\end{document}

The approach is to redefine the floating environment and adjust the functionality of \caption and \label. The former writes stuff to the ToC/LoT (which we're not interested in) and the latter is used to reference the table. So, we nullify \caption and make \label rather store it's argument for later use. Then we manually step the table counter and \recall@label so the correct \label is set and can be referenced.

A similar procedure would hold for other floats. If hyperref is used, there might be more work required. The same possibly goes for any other cross-reference package that might be in use.

share|improve this answer
    
Thanks. Now I get errors about \subcaption, \ContinuedFloat, and \phantomcaption called outside of float. –  Richard Herron Sep 13 '13 at 17:01
1  
@RichardHerron: Please provide a complete, minimal working example (MWE) that replicates your situation as an edit to your question. –  Werner Sep 13 '13 at 17:09
1  
This is the solution as asked. I'm getting increasingly wary of complicated solutions for my own sanity. I think at this point the clearer solution is to get new coauthors. –  Richard Herron Sep 13 '13 at 17:18
add comment

I think I misunderstood something: references to tables work well in latex2rtf.

I make my references work using a slightly different syntax to yours, but I never require any extra packages:

\documentclass{article}
\begin{document}

Table~\ref{tab:widgets} blah blah: 

\begin{table}[!h]
\centering
\caption{\label{tab:widgets}An example table.}
\begin{tabular}{l|r}
Item & Quantity \\\hline
Widgets & 42 \\
Gadgets & 13
\end{tabular}
\end{table}

\end{document}

Call this document Tref.tex or similar:

$> latex Tref.tex
$> latex Tref.tex
$> latex2rtf Tref.tex

You can then open the .rtf file in MS Word and this reference works, possibly after you hit ctrl-a and F9 (select all, update).

I think I must have missed something... Was this not what you needed?

share|improve this answer
    
You're right that the references work fine. But the tables come through as garbage (at least mine do, maybe because of ifmmode and other macro calls) and I wanted to avoid having to manually remove them. In fact, they often crash latex2rtf. My partial solution is to wrap tabular environments in verbatim environments. Then I find the associated table and cut-and-paste. –  Richard Herron Sep 16 '13 at 12:42
1  
Seems like the question then is why use ifmode. My solution for latex2rtf is to use the simplest possible source. I'm not meaning to be difficult, but the answer might be to change your approach, rather than fix this approach..? –  Andy Clifton Sep 16 '13 at 16:45
    
For a .rtf file that includes references into a table and out of a table, please see this repository: github.com/AndyClifton/AccessibleMetaClass –  Andy Clifton Sep 16 '13 at 18:32
    
Yes, I agree completely. After this ordeal I have pared down use of less common packages. The tables with ifmmode come from the Stata package estout, which is a big part of my workflow and otherwise a godsend. estout also prints tables to .rtf and .csv, so I think when I come across cases like this (coauthors joining a paper later in the cycle, but that aren't LaTeX users) I'll verbatim out the tables, latex2rtf the document, and write the tables to .rtf in Stata and add them back downstream. –  Richard Herron Sep 16 '13 at 18:44
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.