markup export commands

Librairie C++ de calcul formel/ C++ symbolic computation library

Modérateur : xcasadmin

Répondre
lukamar
Messages : 331
Inscription : ven. juin 30, 2017 9:55 am
Localisation : Zagreb, Croatia

markup export commands

Message par lukamar » dim. sept. 08, 2019 2:46 pm

Hello Bernard,
I got my markup routines working fine after several bugfixes which I've committed today. As for tex.cc/h, they should be modified as follows (from the original version before the inclusion of markup.cc/h):
tex.cc:
1. Before "#ifndef NO_NAMESPACE_GIAC namespace giac {", insert

Code : Tout sélectionner

#if defined USE_GMP_REPLACEMENTS || defined GIAC_GGB || defined EMCC
inline bool has_improved_latex_export(const gen &g,string &s,GIAC_CONTEXT) { return false; }
#else
#include "markup.h"
#endif
2. After "string gen2tex(const gen & e,GIAC_CONTEXT){", insert

Code : Tout sélectionner

string s;
if (use_improved_latex_export && has_improved_latex_export(e,s,contextptr))
  return s;
tex.h:
Before "std::string gen2tex(const gen & e,GIAC_CONTEXT);", insert

Code : Tout sélectionner

static bool use_improved_latex_export=true;
That's it. Now gen2tex uses the improved latex export unless use_improved_latex_export is set to false. Therefore the output in texmacs sessions is also improved.

Since texmacs uses a heuristic trying to detect and typeset implied multiplication when importing latex code, markup.h provides the routine enable_texmacs_compatible_latex_export(bool yes) which should be called with yes=true for texmacs compatibility (currently enabled by default) or with yes=false to put a thin space whenever a multiplication is implied (if typesetting is done by LaTeX itself). Using texmacs compatibility prevents multiple thin spaces instead of a single one in texmacs sessions.

Maybe a switch -texmacs-compatible-latex-output or something similar could be included when running the giac executable to enable the compatibility at startup. Hence the texmacs plugin for Giac could be modified to use the switch, and the compatibility would be disabled by default.

As for mathml export, there is a new command export_mathml which uses the improved export routines. Its second argument may be "display" for presentation markup or "content" for content MathML. By default, it exports both within a "semantics" block.

[Edit] I have also updated the docs (cascmd_en.tex and aide_cas).

parisse
Messages : 5731
Inscription : mar. déc. 20, 2005 4:02 pm
Contact :

Re: markup export commands

Message par parisse » lun. sept. 09, 2019 11:18 am

In the current unstable source, has_improved_latex_export is always called, is there any reason not to call it if it's available? If not, it's probably better not to add this boolean variable (and if we still want to define it, it must not be declared static nor initialized in tex.h)
Regarding

Code : Tout sélectionner

#if defined USE_GMP_REPLACEMENTS || defined GIAC_GGB || defined EMCC
  bool has_improved_latex_export(const gen &g,string &s,GIAC_CONTEXT){
    return false;
  }
#endif
it's defined juste before _latex in tex.cc, inside the giac namespace, and the declaration is in tex.h without ifdef inside the giac namespace.
I did not understand what you want for texmacs. icas has already a --texmacs flag (and is called from texmacs that way I believe), we can add whatever initialization you need there (line 1350 in icas.cc)

lukamar
Messages : 331
Inscription : ven. juin 30, 2017 9:55 am
Localisation : Zagreb, Croatia

Re: markup export commands

Message par lukamar » lun. sept. 09, 2019 8:14 pm

Yes, there's actually no reason not to call has_improved_latex_export, so boolean variable is not needed. It is only needed to move the call from _latex to gen2tex in the current unstable source. Therefore the portion of tex.cc after line 1314 should look like

Code : Tout sélectionner

#if defined USE_GMP_REPLACEMENTS || defined GIAC_GGB || defined EMCC
  bool has_improved_latex_export(const gen &g,string &s,GIAC_CONTEXT){
    return false;
  }
#endif
  // assume math mode enabled
  string gen2tex(const gen & e,GIAC_CONTEXT){
    string s;
    if (has_improved_latex_export(e,s,contextptr))
      return s;
    switch (e.type){
    case _INT_: case _ZINT: case _REAL:
      if (e.subtype==_INT_BOOLEAN)
	return "\\mbox{"+e.print(contextptr)+'}';      
      return e.print(contextptr);
    case _DOUBLE_:
      if (specialtexprint_double(contextptr))
	return double2tex(e._DOUBLE_val);
      else
	return e.print(contextptr);
    case _CPLX:
      return e.print(contextptr);
    case _IDNT:
      return idnt2tex(e,contextptr);
    case _SYMB:
      return symbolic2tex(*e._SYMBptr,contextptr);
    case _VECT:
      if (e.subtype==_SPREAD__VECT)
	return spread2tex(*e._VECTptr,1,contextptr);
      if (e.subtype==_GRAPH__VECT){
	string s;
	if (is_graphe(e,s,contextptr))
	  return "\\mbox{"+s+'}';
      }
      if (!e._VECTptr->empty() && e._VECTptr->back().is_symb_of_sommet(at_pnt) && !is3d(e._VECTptr->back()) )
	return vectpnt2tex(e,contextptr);
      if (ckmatrix(*e._VECTptr))
	return matrix2tex(*e._VECTptr,contextptr);
      else
	return _VECT2tex(*e._VECTptr,e.subtype,contextptr);
    case _POLY:
      return mbox_begin+string("polynome")+mbox_end+" "; 
    case _SPOL1:
      return gen2tex(spol12gen(*e._SPOL1ptr,contextptr),contextptr);
    case _FRAC:
      return string("\\frac{")+gen2tex(e._FRACptr->num,contextptr)+"}{"+gen2tex(e._FRACptr->den,contextptr)+'}';
    case _EXT: 
      return "";
    case _STRNG:
      return idnt2tex(*e._STRNGptr);
    case _FUNC:
      return idnt2tex(e.print(contextptr));
    case _USER:
      return e._USERptr->texprint(contextptr);
    case _MOD:
      return gen2tex(*e._MODptr,contextptr)+"\\%"+gen2tex(*(e._MODptr+1),contextptr);
    case _POINTER_:
      if (e.subtype==_FL_WIDGET_POINTER &&fl_widget_texprint_function )
	return fl_widget_texprint_function(e._POINTER_val);
      return "Done";
    default:
      return "Error in Tex conversion for "+e.print(contextptr);
    }
    return 0;
  }
  gen _latex(const gen & g,GIAC_CONTEXT){
    if ( g.type==_STRNG && g.subtype==-1) return  g;
#if !defined NSPIRE && !defined FXCG
    if (!secure_run && g.type==_VECT && g.subtype==_SEQ__VECT && g._VECTptr->size()==2 && (*g._VECTptr)[1].type==_STRNG){
      ofstream of((*g._VECTptr)[1]._STRNGptr->c_str());
      of << gen2tex(g._VECTptr->front(),contextptr) << endl;
      return plus_one;
    }
#endif
    return string2gen(gen2tex(g,contextptr),false);
  }
markup.h should be included in icas.cc, after #include "input_lexer.h". Also, from line 1350 the code should look like this:

Code : Tout sélectionner

  /* *********************************************************
     *                       BEGIN TEXMACS                  *
     ********************************************************* */
  if ( intexmacs){
    giac::html_help_init(ARGV[0],false);
    giac::enable_texmacs_compatible_latex_export(true);
    ...
I also made some modifications to markup.cc.

The modification of icas.cc is needed so that the typesetting of giac output in texmacs sessions looks the same as rendered by e.g. pdflatex from the code returned by _latex in Xcas.

lukamar
Messages : 331
Inscription : ven. juin 30, 2017 9:55 am
Localisation : Zagreb, Croatia

Re: markup export commands

Message par lukamar » mar. sept. 10, 2019 8:07 am

I had to make a change in the declaration of has_improved_latex_export, hence tex.cc/h have to be modified accordingly. The modified files are attached below so you can just copy them over the current ones.
Now has_improved_latex_export is called from _latex too, this way the output from _latex is the same in Xcas as in a texmacs session.
Pièces jointes
tex.zip
(17.78 Kio) Téléchargé 153 fois

parisse
Messages : 5731
Inscription : mar. déc. 20, 2005 4:02 pm
Contact :

Re: markup export commands

Message par parisse » mer. sept. 11, 2019 10:56 am

Ok, I have done a few changes, because I prefer not to include markup.h.
I'm also replacing endl with '\n' in the source to ease porting on platforms where I want to replace standard streams by something simpler, could you do the same in your source files?

lukamar
Messages : 331
Inscription : ven. juin 30, 2017 9:55 am
Localisation : Zagreb, Croatia

Re: markup export commands

Message par lukamar » mer. sept. 11, 2019 3:19 pm

Thanks. No problem, I'll replace endl by "\n" in my source later today.
By the way, I've noticed that cobyla algorithm has a heavy output on stderr, which is shown in texmacs sessions. Could it be made quiet when --texmacs option is present? I can help with this if you suggest how it should be done. It would be ideal if stderr could be disabled altogether somehow.

parisse
Messages : 5731
Inscription : mar. déc. 20, 2005 4:02 pm
Contact :

Re: markup export commands

Message par parisse » jeu. sept. 12, 2019 9:29 am

I have changed solve.cc line 7895 to:

Code : Tout sélectionner

    int n=variables.size(),m=con.size(),message(debug_infolevel),maxfun(1000);
That way output is controlled by setting debug_infolevel (and default is no output)

lukamar
Messages : 331
Inscription : ven. juin 30, 2017 9:55 am
Localisation : Zagreb, Croatia

Re: markup export commands

Message par lukamar » jeu. sept. 12, 2019 1:24 pm

Great, it works, thanks!

lukamar
Messages : 331
Inscription : ven. juin 30, 2017 9:55 am
Localisation : Zagreb, Croatia

Re: markup export commands

Message par lukamar » sam. sept. 14, 2019 7:34 pm

Hi,
can you please update markup.cc/h, cascmd_en.tex and aide_cas? I fixed some bugs, added support for piecewise functions and a command xml_print for indenting XML code.

parisse
Messages : 5731
Inscription : mar. déc. 20, 2005 4:02 pm
Contact :

Re: markup export commands

Message par parisse » lun. sept. 16, 2019 2:45 pm

Thanks! Source should be updated.

lukamar
Messages : 331
Inscription : ven. juin 30, 2017 9:55 am
Localisation : Zagreb, Croatia

Re: markup export commands

Message par lukamar » lun. sept. 16, 2019 5:15 pm

I have fixed couple of bugs in xml_print and added one more example to the entry in cascmd_en.tex.
I also suggest replacing the lines 1361-1368 in icas.cc with

Code : Tout sélectionner

printf("latex:");
format_plugin();
printf("{\\centering\\begin{tabular}{|c|}\\hline Giac CAS for TeXmacs, released under the GPL license (3.0)\\\\See \\url{http://www.gnu.org} for license details\\\\May contain BSD licensed software parts (lapack, atlas, tinymt)\\\\\\copyright\\ 2003--2018 B. Parisse \\& al (giac), J. van der Hoeven (TeXmacs)\\\\\\hline\\end{tabular}\\par}");
putchar(TEXMACS_DATA_END);
putchar(TEXMACS_DATA_BEGIN);
printf("verbatim:\n\n");
This prints a nicer banner in texmacs, which is centered and boxed.

parisse
Messages : 5731
Inscription : mar. déc. 20, 2005 4:02 pm
Contact :

Re: markup export commands

Message par parisse » mer. sept. 18, 2019 12:30 pm

Thanks! Should be in unstable source archive.

lukamar
Messages : 331
Inscription : ven. juin 30, 2017 9:55 am
Localisation : Zagreb, Croatia

Re: markup export commands

Message par lukamar » ven. nov. 08, 2019 7:48 pm

Hi Bernard,
can you please delete lines 1365-1366 in icas.cc? These belong to the old banner code.

parisse
Messages : 5731
Inscription : mar. déc. 20, 2005 4:02 pm
Contact :

Re: markup export commands

Message par parisse » sam. nov. 09, 2019 4:32 pm

Since I did some modifications in icas.cc, it would be safer if you could copy/paste the lines that should be deleted.

lukamar
Messages : 331
Inscription : ven. juin 30, 2017 9:55 am
Localisation : Zagreb, Croatia

Re: markup export commands

Message par lukamar » dim. nov. 10, 2019 8:18 am

I was referring to the following lines:

Code : Tout sélectionner

    printf("verbatim:");
    format_plugin();

Répondre