angerhang / mockDoc

0 stars 0 forks source link

\symdef counters for sTeX #9

Open kohlhase opened 9 years ago

kohlhase commented 9 years ago

Write a sample sTeX document with a single \symdef and use the defined symbol once. Then they should go into the bindings and change ```\symdef so that LaTeXML keeps a list of all defined symbols, as well as a count of how many times they are used.

Next, they can add a macro \symreport that prints those counts as a table. And extend the sample document to several \symdef declarations and several uses of the symbols, to see that their code works.

All of the binding work should belong into modules.sty.ltxml and you should do it on your own sTeX branch (and/or fork).

angerhang commented 9 years ago

@dginev I just gave you the access to the repository. I have written a sample tex file mockDoc.tex which uses \symdef, in my sTeX fork, but I am kinda stuck now. As the task indicates, I should count how many times symdef is used. If I understand this correctly, I am supposed to print the count somewhere in the generated omdoc by modifying modules.sty.lxml?

dginev commented 9 years ago

Start with adding:

print STDERR $variable_of_interest, "\n";

all over modules.sty.ltxml, so that you learn more about what is inside there. If you want to pretty print complex objects the best Perl 5 way of doing that is by importing Data::Dumper: use Data::Dumper;

and then print with Dumper the vars of interest:

print STDERR Dumper($variable_of_interest), "\n";

There are some pretty complex objects in LaTeXML, so be prepared to see multi-screen printouts for Dumper of vars such as $whatsit.

angerhang commented 9 years ago

@dginev I am not sure where should I store all the defined symbols, maybe adding an attribute to the root or something?

A hacky way of creating symreport without storing all the defined symbols is to apply findnode on the whole document, but this is rather inefficient.

dginev commented 9 years ago

As this was an example task, I would suggest just doing a "print STDERR" so that you see the number of symdefs in the log of the processing. No need to store it in the OMDoc result.

dginev commented 9 years ago

Oh, but now I see that Michael wanted a \symreport implemented. You should best discuss with him how he wants that represented in the final document.

dginev commented 9 years ago

For storing the symbols during runtime just use LaTeXML's AssignValue and LookupValue macros, there are many examples in the bindings.

angerhang commented 9 years ago

In angerhang/sTeX@b2c7dc92d6349c9fc360bdcf29fe1a2962288f90, I partially finished the task in the following way. So we pass the the name of a \symdef to `\symreport, and the count of that symbol will be printed in the log file. It is true that the output is not nice yet, we have to manually grep of output from the log, but just to show the functionality.

The tex file

\begin{module}[id=magma] 
  \importmodule[\backmods{functions}]{functions}
  \symdef{magbase}{G}
  \symdef{megbase}{M}
  \begin{definition}[id=magma.def]
    $\magbase \magbase \magbase \magbase \magbase$ 
    $\megbase$
    \symreport[magbase] 
    \symreport[megbase]
 \end{definition}
\end{module} 

The output

Symbol magbase use count: 5
Symbol megbase use count: 1
angerhang commented 9 years ago

@kohlhase Can you clarify what kind of presentation you want in the final document?

kohlhase commented 9 years ago

I think that the output is fine in principle (after all, this is mostly an excercise for getting you into the modules.sty.ltxml code. I would like to have an extended output:

Symbol magbase from module magma (macro \magbase) use count: 5

So that the symdef

  \symdef[name=foo]{magbase}{G}

would generate

Symbol foo from module magma (macro \magbase) use count: 5
kohlhase commented 9 years ago

@dginev, could you please have a look at the code if this is reasonable? I think that grepping the log file (that is what I understand Hang is doing) is not the right approach. I would like to have an internal counter I think.

kohlhase commented 9 years ago

Also I would like to have this extended to the \symvariant macro, and have a finer reporting on the variants. Given

\symdef{foo}[1]{#1foo}
\symvariant{foo}[1]{bar}{#1foobar}

I would like to have something like

Symbol foo from module magma (macro \magbase) use count: 5 [default]=3, [bar]=2.

Just to get you even further into the code.

dginev commented 9 years ago

From what I am seeing, the code is exactly in modules.sty.ltxml where it belongs and it does the right thing. The counters are global and count the names irrespective of the module, which is what I would have expected for a first task.

Well done!

angerhang commented 9 years ago

Thanks Deyan for the encouragement : )

angerhang commented 9 years ago

I completed the two extensions in the following ways: for symdef with a name,

  \symdef[name=foo]{trial}{star}

we pass one optional argument to symreport to specify which macro we need

 \symreport[foo]{trial}    

then we get

Info:symreport: Symbol foo from module magma(macro \trial) use count: 1 [default] 1

as expected.

angerhang commented 9 years ago

For symdef with variant,

\symdef{magbase}{G}   
\symvariant{magbase}{uv}{GG}
 $\magbase \magbase  $    
 $\magbase[uv] \trial$ 

we get

Info:symreport: Symbol magbase from module magma(macro \magbase) use count: 3 [default] 2 [uv] 1

as expected.

angerhang commented 9 years ago

The changes were made in angerhang/sTeX@38ad59b74e47653b9f304daccb0af54e3d4a1cef.

angerhang commented 9 years ago

@dginev can you help me inspect if the code is what we want?

angerhang commented 9 years ago

@kohlhase one more question, after this exercise task is complete. Should we merge the changes into KWARC's fork and document the use of the symreportsomewhere, or should we just leave it and discard the changes in my fork?

angerhang commented 9 years ago

@dginev Actually the current symreport is flawed.
Given

\symdef[name=foo]{trial}{...}
\symdef{foo}{.....}

and we call

$\foo \foo \trial $
\symreport{foo}

I am not sure if I understand this correct? The desired output is the following?

Info:symreport: Symbol foo from module magma(macro \foo, trial) use count: 3 [default] 3