angerhang / mockDoc

0 stars 0 forks source link

doc.cls.ltxml #3

Closed kohlhase closed 9 years ago

kohlhase commented 9 years ago

now you should make a LaTeXML binding doc.cls.ltxml for the class. This is going to be more difficult. Especially, since you also need a RelaxNG schema (see #4) for this as well before this can run (we talked about this).

jinbozz commented 9 years ago

I checked article.cls.ltxml.At the beginning, it uses:

use strict; use LaTeXML::Package; package LaTeXML::Package::Pool;

Can I use these packages?

From LaTeXML::Package, I also checked package.pm, It's really LOTS of lines...Do I need to understand what's in it?

One paticular line in article.cls confuses me:

The core sectioning commands are defined in LaTeX.pm

So I checked this file, still, can't understand as usual. How latexml load this file? Automatically?

Jinbo

kohlhase commented 9 years ago

Maybe we should briefly meet and discuss again. I am free today until 16:00 and most of tomorrow.

dginev commented 9 years ago

LaTeXML::Package provides you the DSL of LaTeXML - the special commands for defining the various TeX macros and constructors. You don't need to understand its source, but you should read the documentation to get a first idea. Also for the docs, don't worry if you don't understand everything right away.

General customization: http://dlmf.nist.gov/LaTeXML/manual/customization/customization.latexml.html

Package specifics: http://dlmf.nist.gov/LaTeXML/manual/modules/LaTeXML_Package.html

dginev commented 9 years ago

The core LaTeX commands are explicitly loaded by article.cls right here: https://github.com/brucemiller/LaTeXML/blob/master/lib/LaTeXML/Package/article.cls.ltxml#L18

jinbozz commented 9 years ago

In a nutshell, 3 main problems are unsolved:

  1. 'autoClose' doesn't function properly.
  2. Every empty space is missing.
  3. After adding namespace, I am not sure whether it will have conflict with schema, for now I just didn't use namespace.

I think I need some help in the problems above, Thank you in advance.

jinbozz commented 9 years ago

@angerhang http://search.cpan.org/~brmiller/LaTeXML-0.8.0/ You need to install LaTeXML properly, Error 127 is caused by your computer.

dginev commented 9 years ago

In case anyone wants code reviews / support from me, please push your code on GitHub and provide precise code references together with the relevant error reports.

kohlhase commented 9 years ago

you need to use the namespace. The registration looks OK, but the elements like

must use it e.g. as in mock:section. Otherwise the schema does not apply and the autoclose cannot work.

kohlhase commented 9 years ago

And Deyan is right, you have to make much more precise error reports, what goes wrong, where (code lines) you suspect the error is, ...

It may be a good idea to make separate issues for the respective problems and mention whom you want advice from in the issue. Also copy the errors from the log file into the issue or the false results and what you want to get.

jinbozz commented 9 years ago

@dginev Thank you for your advice. I made a small file of this issue.

After a warm conversation between Michael, Hang and me, we solved most problem. "No obvious problems" when compiling. However, one error is still remaining, and I need your help.

There's no proper empty spaces in the produced XML document.

Related documents:

mockDoc.tex:

\documentclass{doc}
\begin{document}
    \section{A brief introduction}
        Percy Bysshe Shelley was one of the major English Romantic poets.
\end{document}

XML document:

<?xml version="1.0" encoding="UTF-8"?>
<?latexml searchpaths="/home/la_stravaganza/repos/mockDoc/Issue#3"?>
<?latexml class="doc"?>
<?latexml RelaxNGSchema="mockDoc.rng"?>
<mock:document xmlns:mock="https://kwarc.info/projects/mockDoc">
  <mock:section>
    <mock:title>Abriefintroduction</mock:title>
    <mock:p>PercyByssheShelleywasoneofthemajorEnglishRomanticpoets.</mock:p>
  </mock:section>
</mock:document>

doc.cls.ltxml:


package LaTeXML::Package::Pool;
use strict;
use LaTeXML::Package;
use warnings;

#Document Structure 
RegisterNamespace('mock'=>"https://kwarc.info/projects/mockDoc");
RelaxNGSchema("mockDoc.rng",'mock'=>"https://kwarc.info/projects/mockDoc");

#---------------------------------------------------------------------
DefEnvironment('{document}', "<mock:document>#body</mock:document>");
DefConstructor('\section{}', "<mock:section><mock:title>#1</mock:title>");
DefConstructor('\subsection{}', "<mock:subsection><mock:title>#1</mock:title>");
DefConstructor('\paragraph{}', "<mock:paragraph><mock:title>#1</mock:title><mock:p>");
DefConstructor('\newline', "<mock:break/>");

#autoClose
Tag('mock:paragraph', autoClose=>1);
Tag('mock:section', autoClose=>1);
Tag('mock:subsection', autoClose=>1);
Tag('mock:p', autoClose=>1);
Tag('mock:p', autoOpen=>1);

#make sure Perl work 
1;

mockDoc.xml.log:

(Loading /usr/local/share/perl/5.18.2/LaTeXML/Package/TeX.pool.ltxml... (Loading /usr/local/share/perl/5.18.2/LaTeXML/Package/eTeX.pool.ltxml... 0.00 sec) (Loading /usr/local/share/perl/5.18.2/LaTeXML/Package/pdfTeX.pool.ltxml... 0.01 sec) 0.14 sec) latexmlc (LaTeXML version 0.8.0) processing started Tue Feb 10 22:26:01 2015

(Digesting TeX mockDoc... (Processing content /home/la_stravaganza/repos/mockDoc/Issue#3/mockDoc.tex... (Loading /usr/local/share/perl/5.18.2/LaTeXML/Package/LaTeX.pool.ltxml... 0.13 sec) (Loading /home/la_stravaganza/repos/mockDoc/Issue#3/doc.cls.ltxml... 0.00 sec) 0.14 sec) 0.15 sec) (Building... (Loading RelaxNG mockDoc.rng... (Loading RelaxNG schema from mockDoc.rng... 0.00 sec) 0.01 sec). 0.03 sec) (Rewriting... 0.00 sec) (Finalizing... 0.00 sec) Conversion complete: No obvious problems. Status:conversion:0

You can also find other files in /Issue#3, if necessary.

dginev commented 9 years ago

Excellent report! I can tell you what went wrong after 10 seconds of reading through your issue, since I have all the data in front of me. In fact, I have hit the same problem some years back when working on the omdoc.cls.ltxml redefinition of the {document} environment.

What you need to remember: The LaTeX {document} environment has a variety of associated hooks, one of which ties with the LaTeX preamble flag. In LaTeX preambles, space is a neutral character, i.e. it gets discarded by the TeX processor. Which is why the {document} environment needs to explicitly mark the end of the preamble before any digestion of the body takes place, as is done here: https://github.com/brucemiller/LaTeXML/blob/master/lib/LaTeXML/Package/LaTeX.pool.ltxml#L280

If you copy that line in your binding the spaces will reappear.

A good rule of thumb is that whenever you are modifying environments/macros/constructors that have a native TeX/LaTeX implementation, you should copy the entire implementation over and adapt it carefully, so that you do not lose core functionality.

jinbozz commented 9 years ago

Thank you Deyan, I solved it. I think this issue could be closed now.

kohlhase commented 9 years ago

@dginev thanks for the help, I had remembered that we had seen the problem before, but could not remember that was the cause or the cure. But you did wonderful.