
\chapter{Compatibility with LaTeX}

Although {\TeXmacs} has not been designed to be fully compatible with
{\LaTeX}, it is possible to convert documents from {\TeXmacs} to {\LaTeX}
and \emph{vice versa}, although the result will not always be perfect.
Also, conversions from {\TeXmacs} to {\LaTeX} will generally yield
better results then conversions the other way around.
In particular, {\TeXmacs} may reasonably well be used to write articles,
which need to be converted to {\LaTeX} for submission purposes.
In this chapter, we will describe more precisely the conversion mechanisms,
which will help you to obtain a result as satisfactory as possible.

\section{Conversion from TeXmacs to LaTeX}

The most common situation is that you want to convert an article
from {\TeXmacs} to {\LaTeX}, in order to submit it to some journal.
Given a {\TeXmacs} file ¤name.tm¤, you may convert it into
a {\LaTeX} file ¤name.tex¤ using \subsubmenu{File}{export}{latex}.
At a first stage, you may try to run {\LaTeX} on ¤name.tex¤,
and see whether you obtain a satisfactory result. If so,
then you should submit ¤name.tex¤ together with the style file ¤TeXmacs.sty¤,
which can be found in the directory ¤$TEXMACS_PATH/misc/latex¤. %$

Often, the journal to which you submit uses its own style file,
say ¤journal.sty¤. In that case, you should also copy the file
\begin{verbatim}
    $TEXMACS_PATH/styles/article.ts
\end{verbatim}%$
to
\begin{verbatim}
    ~/.TeXmacs/styles/journal.ts
\end{verbatim}
and use ¤journal¤ as your document style in
\subsubmenu{Document}{style}{other}. You may optionally edit ¤journal.ts¤,
so that the article layout becomes closer to the journal's style.
In some cases, you also have to create a new copy of ¤TeXmacs.sty¤,
and modify some of the environments for compatibility with
the journal's style file ¤journal.sty¤.

If your first try to convert your document into {\LaTeX}
did not yield a satisfactory result, then you will usually observe
that only minor parts of the texts were not converted correctly.
This may be due to three main reasons:
\begin{itemize}
  \item Your text uses some specific {\TeXmacs} features.
  \item You used a {\TeXmacs} feature, which has not yet been
        implemented in the conversion algorithm.
  \item You found a bug in the conversion algorithm.
\end{itemize}
These issues will be discussed in more detail in the next section.

In case of problems, a naive strategy would be to correct
the produced {\LaTeX} file and to send it to the journal.
However, this strategy has the disadvantage that you have
to make these corrections over and over again,
each time that you convert your {\TeXmacs} file ¤name.tm¤,
after having made some extra modifications.
A better strategy is to use the \subsubmenu{Insert}{specific}{latex}
and \subsubmenu{Insert}{specific}{texmacs} constructs to write text
which is visible in the converted resp. original file only.

For instance, assume that the word ``blauwbilgorgel'' is hyphenated
correctly in the {\TeXmacs} source, but not in the {\LaTeX} conversion.
Then you may proceed as follows:
\begin{enumerate}
  \item Select ``blauwbilgorgel''.
  \item Click on \subsubmenu{Insert}{specific}{texmacs}
        to make the text ``blauwbilgorgel'' {\TeXmacs}-specific.
  \item Click on \subsubmenu{Insert}{specific}{latex}.
  \item Type the latex code ¤blauw\-bil\-gor\-gel¤
        with the correct hyphenation.
  \item Press \key{return} to activate the {\LaTeX}-specific text.
\end{enumerate}
In a similar fashion, you may insert {\LaTeX}-specific line breaks,
page breaks, vertical space, style parameter modifications, etc.

\section{Possible sources of conversion problems}

\subsection{Specific TeXmacs features}

Some {\TeXmacs} typesetting primitives have no analogues in {\LaTeX},
and the conversion algorithm will simply transform them into blank space.
Some main features which are specific to {\TeXmacs} are the following:
\begin{itemize}
  \item Left primes.
  \item Big separators between big parentheses.
  \item Mosaics.
  \item Trees.
  \item Complex user macros.
  \item Vertical spaces ``before'' and ``after''.
  \item Indentation flags ``before'' and ``after''.
\end{itemize}
You should avoid to use these specific {\TeXmacs} features,
if your document needs to be converted into {\LaTeX}.
Nevertheless, in the far future, the conversion program
might generate encapsulated postscript by default of
a more intelligible translation.

\subsection{Not yet implemented conversions}

Although we try to keep the conversion algorithm as complete as
possible for your needs, certain things have not yet been implemented.
Some examples of not yet implemented issues are
\begin{itemize}
  \item Non standard fonts.
  \item Conversion of tabulars.
  \item Style parameters.
\end{itemize}
Any suggestion about desirable extensions of the conversion algorithm
should be reported to
\begin{verbatim}
    TeXmacs@math.u-psud.fr
\end{verbatim}
and we will try to incorporate it as quickly as possible.
It may take some time to implement the correct conversion of style parameters,
since these are not the same in {\TeXmacs} and {\LaTeX}. Furthermore,
layout differences between {\TeXmacs} and {\LaTeX} can not entirely
be eliminated.

\subsection{Bugs in the conversion algorithm}

The most annoying situation if when a converted {\TeXmacs} document
produces lots of errors at the compilation or if the result has
nothing to do with the original. In that case you have probably
detected a bug in the conversion algorithm (or in the installation
of {\LaTeX} on your system). Please try to figure out the source
of the bug in this case and report it by sending an email to
\begin{verbatim}
    TeXmacs@math.u-psud.fr
\end{verbatim}

\section{Conversion from LaTeX to TeXmacs}

The current aim of the conversion program from {\LaTeX} to {\TeXmacs},
is to \emph{help} you in translating old documents into {\TeXmacs}.
\emph{Grosso modo}, conversions from {\LaTeX} to {\TeXmacs}
are more problematic than conversions the other way around.
Nevertheless, as long as you restrict yourself to using
the most common {\LaTeX} commands, you should be able
to convert your old documents reasonably well.
For example, all {\TeXmacs} help files have been written
in {\LaTeX} in order to validate the {\LaTeX} to {\TeXmacs}
conversion program.

You may convert a {\LaTeX} document ¤name.tex¤ into {\TeXmacs}
using \subsubmenu{File}{import}{latex} and save it under ¤name.tm¤.
If your {\LaTeX} document was written sufficiently well,
then the converted result should be more or less acceptable,
apart from certain unrecognized commands, which appear in red.
A good solution would be to write your own style file for converted
documents, based on the original style, and in which the unrecognized
commands are defined.

However, in certain less fortunate cases, the converted document
will look like a great mess. This usually stems from the fact
that {\TeX} and {\LaTeX} allow users to modify the parser dynamically,
for instance using the ¤\catcode¤ command. In this case,
the conversion program may get confused,
by making erroneous assumptions on the mode or the environment.
As a result, text may be converted as mathematics,
mathematics as verbatim, and so on.
Nevertheless, the commands in your source file ¤name.tex¤
which confused the conversion program are usually easily localized
by comparing the {\LaTeX} source with its {\TeXmacs} conversion.
Modulo some hacking of the source, you should be able to
remove the litigious code, so that the document converts
reasonably well.

In the future, we also plan to extend the conversion program
with a style file converter and some additional features
which facilitate the translation of user defined commands,
which are defined in another document than the one you want to convert.
