<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!DOCTYPE document PUBLIC "-//CNX//DTD CNXML 0.5 plus MathML//EN" "http://cnx.rice.edu/technology/cnxml/schema/dtd/0.5/cnxml_mathml.dtd">
<document xmlns="http://cnx.rice.edu/cnxml" xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" xmlns:m="http://www.w3.org/1998/Math/MathML" id="new">
  <name>Using and Troublshooting the LaTeX-CNXML Importer</name>
  <metadata>
  <md:version>1.2</md:version>
  <md:created>2008/06/17 10:50:16 GMT-5</md:created>
  <md:revised>2008/07/29 11:18:06.455 GMT-5</md:revised>
  <md:authorlist>
      <md:author id="dcwill">
      <md:firstname>Daniel</md:firstname>
      <md:othername>Collins</md:othername>
      <md:surname>Williamson</md:surname>
      <md:email>dwilliamson1285@gmail.com</md:email>
    </md:author>
  </md:authorlist>

  <md:maintainerlist>
    <md:maintainer id="dcwill">
      <md:firstname>Daniel</md:firstname>
      <md:othername>Collins</md:othername>
      <md:surname>Williamson</md:surname>
      <md:email>dwilliamson1285@gmail.com</md:email>
    </md:maintainer>
    <md:maintainer id="rswagner">
      <md:firstname>Raymond</md:firstname>
      
      <md:surname>Wagner</md:surname>
      <md:email>rwagner@rice.edu</md:email>
    </md:maintainer>
  </md:maintainerlist>
  
  <md:keywordlist>
    <md:keyword>CNXML</md:keyword>
    <md:keyword>content</md:keyword>
    <md:keyword>Importer</md:keyword>
    <md:keyword>Importing</md:keyword>
    <md:keyword>issues</md:keyword>
    <md:keyword>LaTeX</md:keyword>
    <md:keyword>Tralics</md:keyword>
    <md:keyword>troublshooting</md:keyword>
  </md:keywordlist>

  <md:abstract>This module is a beginner's guide to using and troubleshooting the LaTeX-CNXML importer.</md:abstract>
</metadata>
  
<content>

    <para id="delete_me"><name>Abstract</name>This module is a beginner's guide to using and troubleshooting the LaTeX to CNXML importer. It can be used a companion to the Connexions LaTeX Importer tutorial at <link src="http://cnx.org/help/UsingLaTeX">cnx.org/help/UsingLaTeX</link>.
    </para><section id="element-278"><name>How to use the LaTeX Importer</name>
<para id="element-22">One of the first lessons learned when using the LaTeX importer is to abide by the rules. The importer is a rather faithful utility, but it will not function properly unless the LaTeX file is properly prepared. So, the first step to importing your LaTeX document is preparation. 
</para>
<para id="element-100">
Connexions has created a template that will aid you in this process. The template is available for download <link src="http://cnx.org/help/LaTeX_template.tex">here</link>.
</para><section id="element-725"><name>Using the LaTeX Template</name>

<para id="element-101">The importer uses <link src="http://www-sop.inria.fr/apics/tralics/">Tralics</link> to translate LaTeX to CNXML. Tralics supports a large number of LaTeX packages and commands, but not all of them. Using the <link src="http://cnx.org/help/LaTeX_template.tex">Connexions LaTeX Template</link> will increase your chances for a successful import. Follow the steps below to prepare your document.

<list id="importing" type="enumerated"><item>Begin preparing your document by pasting the body of your document between the 
<code>\begin{document}</code> and <code>\end{document}</code> commands in the template.</item>
<item>Un-comment (remove the "%" sign) only the <code>\usepackage{}</code> commands required by your LaTeX document. These are located near the beginning of the template.</item>
<item> If you have any "user-defined macros" you may insert these after the <code>\usepackage{}</code> commands.</item>
<item>At the end of the document you may supply your .bib files. Make sure these files are at the same directory level as the file that is referencing it.
<note id="note-1" type="Note">An issue has been noted with .bib file names containing capital letters. Ensure that your .bib files are labeled in lower-case letters (including the extensions).</note></item>
<item> If your document contains images, make sure these files are at the same directory level as the file that is referencing it.</item>
<item>Save your new template-enhanced file. Make sure to rename the files  and place it in the folder with your .bib and image files.</item>
<item>Run LaTeX (pdflatex) on the new file using only the <code>\usepackage{}</code> commands allowed by the template.</item>
<item> Include the new file, all image files and .bib files in a new .zip file with the same name as your template-enhanced .tex file. Their names <emphasis> must</emphasis> match and there should not be any sub-folders!</item>
</list>

</para></section><section id="element-687"><name>Importing your LaTeX Document</name><para id="element-103">
Once you have successfully completed the steps above, your document should be properly prepared for import in to the Connexions depository. Follow the steps below:
<list id="into-cnx" type="enumerated"><item> In your workspace or workgroup, create a new blank module.</item>
<item>Then from the edit tab of that module, select LaTeX from the import drop-down list and click import.<figure>
<media type="image/png" src="LaTeX import.png"> <param name="print-width" value="3in"/></media></figure></item>
<item> Click browse to locate your .zip file.</item>
<item>Click import to upload your document.</item>
</list>
</para></section>
</section>
<section id="element-853"><name>Troubleshooting your Import</name>
<para id="element-12">This section of the module will serve as a consistently updated resource documenting typical importer issues and errors as well as known solutions.
</para>
<section id="element-199"><name>The Document Imports but there are Errors with the Content</name>
<list id="list-3255" type="named-item"><item><name>Links to outside of the module are missing</name>&lt;cnxn&gt; tags are CNXML's version of LaTeX \ref links.  When you chop a larger LaTeX document up to make modules, the \ref links pointing to objects still inside the new, smaller document will become &lt;cnxn&gt;'s.  Those \ref links pointing to objects now outside of the modularized document will not.  
All non-internal links will have to be inserted manually using <link src="http://cnx.org/eip-help/cnxn">&lt;cnxn&gt;</link> tags. Also, it is important to note that inter-module CNXNs can not be established until the modules have been published and assigned a module number. 
</item>
<item><name>Images are too large or small</name>The importer displays the image at the size of the originally imported image, but it is possible to manipulate the image size inside Connexions. Click on the image and discriptive information will display information. You will notice that the width is displayed in two places. Where it says <emphasis><![CDATA[<param name="width" value="the width of your image"/>]]></emphasis>, you can change the size of the image by adjusting the number.</item>

<item><name>Math text does not display spaces</name>The importer converts all math into presentation MathML. When text is written within the <code>\begin{equation}</code> and <code>\end{equation}</code> tags in the LaTeX file, the text will be interpreted as an "identifier" (<emphasis><![CDATA[<m:mi></m:mi>]]></emphasis>). The result of this error will look like the equation below.
<equation id="uid1111">
<m:math mode="display" overflow="scroll">
<m:mspace width="150pt"/>          
<m:mtable displaystyle="true">
            <m:mtr>
              <m:mtd columnalign="right">
                <m:mi>δ</m:mi>
              </m:mtd>
              <m:mtd>
                <m:mo>=</m:mo>
              </m:mtd>
              <m:mtd columnalign="left">
                <m:mrow>
                  <m:mi>m</m:mi>
                  <m:mi>i</m:mi>
                  <m:mi>n</m:mi>
                  <m:mo>{</m:mo>
                  <m:msub>
                    <m:mi>δ</m:mi>
                    <m:mi>i</m:mi>
                  </m:msub>
                  <m:mo>}</m:mo>
                  <m:mo>,</m:mo>
                  <m:mi>f</m:mi>
                  <m:mi>o</m:mi>
                  <m:mi>r</m:mi>
                  <m:mi>a</m:mi>
                  <m:mi>l</m:mi>
                  <m:mi>l</m:mi>
                  <m:mi>p</m:mi>
                  <m:mi>a</m:mi>
                  <m:mi>s</m:mi>
                  <m:mi>s</m:mi>
                  <m:mi>a</m:mi>
                  <m:mi>n</m:mi>
                  <m:mi>d</m:mi>
                  <m:mi>s</m:mi>
                  <m:mi>t</m:mi>
                  <m:mi>o</m:mi>
                  <m:mi>p</m:mi>
                  <m:mi>b</m:mi>
                  <m:mi>a</m:mi>
                  <m:mi>n</m:mi>
                  <m:mi>d</m:mi>
                  <m:mi>s</m:mi>
                  <m:mi>i</m:mi>
                  
                </m:mrow>
              </m:mtd>
            </m:mtr>
           
          </m:mtable>
<m:mspace width="200pt"/>
        </m:math>
</equation>
To remedy this error, simply remove the MathML that is "writing" the text and replace it with <emphasis><![CDATA[<m:mtext>your text here</m:mtext>]]></emphasis>.</item>

<item><name>Two equations are referenced as a single equation</name>On occasion, the importer will misinterpret two consecutive equations as a single equation. This occurs quite frequently when there is nothing separating the equations. The solution to this error is to simply copy the MathML for the second equation and pasting it into a new equation box.</item>

<item><name>An equation has assimilated  everything following it into MathMl</name>There is a noted bug with Tralics where the converter can not understand where certain equations end. This is especially common with conditional statements such as this:
<equation id="uid2593"><m:math>

<m:mi>a</m:mi>
<m:mo>(</m:mo>
<m:mi>n</m:mi>
<m:mo>)</m:mo>
<m:mo>=</m:mo>
<m:mo>{</m:mo>
<m:munderover>
<m:mtext>h(M)</m:mtext>
<m:mrow>
<m:mn>0</m:mn>
</m:mrow>
<m:mrow>
<m:mi>2h(n)</m:mi>
</m:mrow>
</m:munderover>
<m:mspace width="5pt"/>
<m:munderover>
<m:mtext>for n = M</m:mtext>
<m:mrow>
<m:mtext>otherwise</m:mtext>
</m:mrow>
<m:mrow>
<m:mspace width="10pt"/>
<m:mtext>for</m:mtext>
<m:mspace width="5pt"/>
<m:reln><m:leq/>
<m:reln><m:leq/>
<m:mrow>
<m:mn>0</m:mn>
</m:mrow>

<m:mrow>
<m:mi>n</m:mi>
</m:mrow>

</m:reln>

<m:mrow>
<m:mi>M</m:mi>
<m:mo>-</m:mo>
<m:mn>1</m:mn>
</m:mrow>
</m:reln>
</m:mrow>
</m:munderover>

</m:math>
</equation> 
Statements like this may LaTeX on your computer, but they often result in errors when used with Tralics. Unfortunately, this issue is not a simple fix. Follow the steps below to fix this issue.
<list id="tralics-error" type="enumerated"><item> Locate the culprit equation in your .tex file and comment it out.</item>
<item>Save the file, and place the newly saved file back in your .zip file containing your .bib and image files.</item>
<item> Import the file again.
<note id="note-23" type="Note">
Warning, importing the content again will overwrite any work that you have done previously!
</note>  
</item>
<item> Make certain that the import was successful, paying special attention to the content following the omitted equation.</item>
<item> Manually input the MathML for the conditional statement.
<note id="note-24" type="Note">Hint, using the <![CDATA[<m:munderover></m:munderover>]]> command will help you create this type of conditional statement.
</note>
</item>
</list>
</item></list></section>

<section id="element-661"><name>The Document Does NOT Import</name>

<para id="element-279">These errors are much more difficult to remedy. As of right now, the error message received when a file does not import is generic and gives very little information about what actually caused the import to fail, but this section will provide you with a few known issues that might result in failure.
</para>
<list id="list-239869234" type="named-item"><item><name>Known Tralics Don'ts</name>Certain practices allowed by LaTeX in general are not supported through Tralics. These must be avoided, as they will break the importer. They include:
<list id="list-234" type="bulleted"><item>Placing tables within other tables</item>
<item>Ommitting braces for LaTeX commands when they take a single argument. As an example, consider use of the <code>\sqrt{}</code> command without braces, as in <code>\sqrt\pi</code> instead of <code>\sqrt{\pi}</code>. The latter usage is the only supported technique.</item>
<item>Using different capitalizations on the filenames in <code>\includegraphics{}</code> statements than are used in the actual files they reference in the .zip folder. Though this may work in development on a Windows platform, it will cause an error in the Linux-based importer.</item>
</list></item>

<item><name>Packages Supported by the Tralics importer</name>As mentioned previously, Tralics supports several LaTeX packages, but not all of them. For a complete list of supported packages and sub-packages, visit the Tralics <link src="http://www-sop.inria.fr/apics/tralics/packages.html">website</link>. You may wish to visit this site to determine what packages might be causing the imports failure.</item>
<item><name>Use only the packages you need</name>Occasionally, using packages that are not required by your document can result in errors. Make certain that all of the un-commented <code>\usepackage{}</code> commands are actually <emphasis>required</emphasis> by your document. If you locate any that are not necessary comment them out, save your file and attempt to import the file again.  </item>
<item><name>mbox Issues</name>The <code>\mbox{}</code> command is known to cause issues, especially when more than of these commands occurs in close succession. For example the following lines of LaTeX resulted in the a module's failure to import, even though it was possible to successfully build the file on a Windows platform.
<code type="block">
\be
                    n\phi  =  2K_1i  \ \ \ \mbox{for  i = 0, 1,
                    \dots}
\label{cc24}\ee

From (\ref{cc15}), this gives

\be
             \omega_{zi} =  sn [2K_1i/n,k] , \ \ \ \mbox{i =
             0,1,\dots}
\label{cc25}\ee

This can be reformulated using (\ref{cc18}) so that $n$ and $K_1$ are not
needed. For $N$ odd, the zero locations are

\be
             \omega_{zi}  =  sn [2Ki/N,k] , \ \ \ \mbox{i = 0,1,\dots}
\label{cc26}\ee
</code>
Fortunately, commenting out this section of code made it possible to successfully import the module. The MathML for these equations was added manually after the  import of the rest of the module.</item>
<item><name>Empty Sections</name>An empty section is a portion of the LaTeX file that contains a <code>\section{your text here}</code> command, but lacks any content following it. This sort of empty section is permitted anywhere inside the document except as the final section <emphasis>if the section is followed by a bibliography file</emphasis>. This will break the importer. There is a simple remedy  for this issue. If you do not need the section, simply comment it out and attempt to import again, but if you do need the section header resulting from the command, add text following the marker but before the bibliography. Once you import the file, you can manually delete the text from the paragraph under the section marker, but you can not delete the paragraph. This is prohibited by Connexions. A section <emphasis>must</emphasis> contain something. </item></list></section>


</section><section id="element-232"><name>Conclusion</name><para id="element-325235235">Hopefully this short guide has been helpful. Obviously, this list does not cover all of the possible issues, but this module will serve as a living document continuing to be updated and refined as new issues and solutions become known. If you come across an error that you think is a Tralics based error, please let Connexions know using the <link src="http://cnx.org/bug_submit_form">bug submission form</link>. 
</para></section>
  
  </content>
  
</document>
