PhoenixLecture  2.0.0
Set of tools to make lectures
platexobj_formulae.h File Reference
#include <string>
#include <map>
#include "PPath.h"
#include "dico_replace_var.h"
#include "PLatexObj.h"
#include "platexobj_utils.h"
+ Include dependency graph for platexobj_formulae.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  POutoutMode
 Output mode of the html backend. More...
 

Macros

#define FORMULAE_RECOVER_FILE   ".formulae_recover.map"
 Define the name of the file which contains the formulae and the path to the created file. More...
 

Typedefs

typedef std::map< PString, PStringPMapFormula
 Map of the formulae generated by the ptex2html which can be reused by other PLatexObj which have the same formula. More...
 

Functions

PString platexobj_htmlStrInlineMath (POutoutMode &outputMode, const PLatexObj &obj)
 Convert a PLatexObj into a string. More...
 
PString platexobj_htmlStrLatex (POutoutMode &outputMode, const PLatexObj &obj, const PString &latexEnv)
 Convert a PLatexObj into a string. More...
 
void platexobj_loadFormulaeMap (PMapFormula &mapFormula)
 Load the map file of all the formulae if it exists. More...
 
void platexobj_saveFormulaeMap (const PMapFormula &mapFormula)
 Save the map file of the formulae to avoid extra latex call. More...
 
PString platexobj_theme_createPage (POutoutMode &outputMode)
 Create the page from variables in POutoutMode. More...
 
void platexobj_theme_init_var (POutoutMode &outputMode)
 Initialise basic variables of POutoutMode. More...
 
void platexobj_theme_set_var (POutoutMode &outputMode, const PString &varName, const PString &value)
 Set a variable in the map of variable for theme (will take account the IS_XXX_BEGIN accordingly if the value is empty or not) More...
 
void platexobj_theme_update_var (POutoutMode &outputMode, const PString &pageLink, const PString &pageTitle, const PString &prevSecLink, const PString &prevSecTitle, const PString &nextSecLink, const PString &nextSecTitle, const PString &parentSecLink, const PString &parentSecTitle, const PPath &currentSourceFile, size_t currentSourceLine)
 Update var of POutoutMode for current section. More...
 
void platexobj_update_theme (POutoutMode &outputMode, const PPath &themeBaseFile)
 Update the theme of the generated website. More...
 

Macro Definition Documentation

◆ FORMULAE_RECOVER_FILE

#define FORMULAE_RECOVER_FILE   ".formulae_recover.map"

Define the name of the file which contains the formulae and the path to the created file.

Definition at line 18 of file platexobj_formulae.h.

Typedef Documentation

◆ PMapFormula

typedef std::map<PString,PString> PMapFormula

Map of the formulae generated by the ptex2html which can be reused by other PLatexObj which have the same formula.

Definition at line 21 of file platexobj_formulae.h.

Function Documentation

◆ platexobj_htmlStrInlineMath()

PString platexobj_htmlStrInlineMath ( POutoutMode outputMode,
const PLatexObj obj 
)

Convert a PLatexObj into a string.

Parameters
[out]outputMode: output mode of the html backend
obj: PLatexObj to be converted into a string
Returns
output string which contains the PLatexObj

Definition at line 160 of file platexobj_formulae.cpp.

160  {
161  PString body("");
162  if(outputMode.isMathJaxMode){
163  body += "$"+obj.getText()+"$\n";
164  }else{
165  PString fileNamePng(platexObj_createFormulaTex(outputMode, obj.getId(), "$", obj.getText()));
166  body += "<span class=\"inlineformula\" /><img src=\"" + fileNamePng + "\" alt=\""+obj.getText()+"\" /></span>";
167  }
168  return body;
169 }
long unsigned int getId() const
Gets the id of the PLatexObj.
Definition: PLatexObj.cpp:284
const PString & getText() const
Gets the text of the PLatexObj.
Definition: PLatexObj.cpp:312
Extends the std::string.
Definition: PString.h:16
PString platexObj_createFormulaTex(POutoutMode &outputMode, size_t objId, const PString &latexEnv, const PString &texContent)
Create an image with a latex formula.
bool isMathJaxMode
True to use the MathJax backend, false to use the latex backend.

References PLatexObj::getId(), PLatexObj::getText(), POutoutMode::isMathJaxMode, and platexObj_createFormulaTex().

+ Here is the call graph for this function:

◆ platexobj_htmlStrLatex()

PString platexobj_htmlStrLatex ( POutoutMode outputMode,
const PLatexObj obj,
const PString latexEnv 
)

Convert a PLatexObj into a string.

Parameters
[out]outputMode: output mode of the html backend
obj: PLatexObj to be converted into a string
latexEnv: name of the latex environement to be used
Returns
output string which contains the PLatexObj

Definition at line 144 of file platexobj_formulae.cpp.

144  {
145  PString body("");
146  if(outputMode.isMathJaxMode){
147  body += "$$\\begin{"+latexEnv+"}"+obj.getText()+"\\end{"+latexEnv+"}$$\n";
148  }else{
149  PString fileNamePng(platexObj_createFormulaTex(outputMode, obj.getId(), latexEnv, obj.getText()));
150  body += "<div class=\"formula\" /><img src=\"" + fileNamePng + "\" alt=\"nothing\" /></div>";
151  }
152  return body;
153 }

References PLatexObj::getId(), PLatexObj::getText(), POutoutMode::isMathJaxMode, and platexObj_createFormulaTex().

+ Here is the call graph for this function:

◆ platexobj_loadFormulaeMap()

void platexobj_loadFormulaeMap ( PMapFormula mapFormula)

Load the map file of all the formulae if it exists.

Parameters
[out]mapFormula: map of formulae to be loaded to avoid calling latex too much

Definition at line 20 of file platexobj_formulae.cpp.

20  {
22  if(!data_load(fileName, mapFormula)){return;}
23 }
bool data_load(FILE *iter, T &data)
Load data from a message.
Definition: data_file.h:39
#define FORMULAE_RECOVER_FILE
Define the name of the file which contains the formulae and the path to the created file.

References data_load(), and FORMULAE_RECOVER_FILE.

Referenced by processAllFile().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ platexobj_saveFormulaeMap()

void platexobj_saveFormulaeMap ( const PMapFormula mapFormula)

Save the map file of the formulae to avoid extra latex call.

Parameters
[out]mapFormula: map of formulae to be saved

Definition at line 28 of file platexobj_formulae.cpp.

28  {
30  if(!data_save(fileName, mapFormula)){return;}
31 }
bool data_save(FILE *iter, const T &data)
Save data in a message.
Definition: data_file.h:18

References data_save(), and FORMULAE_RECOVER_FILE.

Referenced by processAllFile().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ platexobj_theme_createPage()

PString platexobj_theme_createPage ( POutoutMode outputMode)

Create the page from variables in POutoutMode.

Parameters
[out]outputMode: POutoutMode to be used
Returns
html page content

Definition at line 266 of file platexobj_formulae.cpp.

266  {
267  PString body("");
268  dico_replace_nested_call(body, outputMode.themeCall, outputMode.mapVar, "${", "}");
269  return body;
270 }
void dico_replace_nested_call(PString &out, const PNestedCall &call, const PMapKnownVar &mapKeyVariable, const PString &varBegin, const PString &varEnd)
Replace the nested call by the variables in map.
PMapKnownVar mapVar
Map of output var which are use to fill the output themes.
PNestedCall themeCall
Parsed theme to be used.

References dico_replace_nested_call(), POutoutMode::mapVar, and POutoutMode::themeCall.

Referenced by platexobj_book_createPage(), and platexobj_bookIndexHtml().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ platexobj_theme_init_var()

void platexobj_theme_init_var ( POutoutMode outputMode)

Initialise basic variables of POutoutMode.

Parameters
[out]outputMode: POutoutMode to init variables

Definition at line 198 of file platexobj_formulae.cpp.

198  {
199  outputMode.mapVar["${STYLE}"] = outputMode.currentStyle;
200  if(outputMode.isBookTheme){
201  platexobj_theme_set_var(outputMode, "AUTHOR_EMAIL", outputMode.bookMail);
202  platexobj_theme_set_var(outputMode, "GITLAB_URL", outputMode.bookGitlabUrl);
203  platexobj_theme_set_var(outputMode, "GITLAB_MASTER_URL", outputMode.bookMasterProjectUrl);
204  outputMode.mapVar["${BOOK_TABLE_OF_CONTENT}"] = "";
205  }
206  PString bibliography("");
207  if(outputMode.isBibliography){
208  bibliography = "bibliography.html";
209  }
210  platexobj_theme_set_var(outputMode, "BIBLIOGRAPHY", bibliography);
211  PString remoteMathjaxFile(""), localMathjax("");
212  if(outputMode.isRemoteMathjax){
213  remoteMathjaxFile = "load-mathjax.js";
214  }else{
215  if(outputMode.isMathJaxMode){
216  localMathjax = "MathJax.js";
217  }
218  }
219  platexobj_theme_set_var(outputMode, "REMOTE_MATHJAX", remoteMathjaxFile);
220  platexobj_theme_set_var(outputMode, "LOCAL_MATHJAX", localMathjax);
221 }
void platexobj_theme_set_var(POutoutMode &outputMode, const PString &varName, const PString &value)
Set a variable in the map of variable for theme (will take account the IS_XXX_BEGIN accordingly if th...
PString bookGitlabUrl
Gitlab url of the current sources of the project.
bool isBookTheme
True to activate the book theme.
PString bookMasterProjectUrl
Master project url in book mode.
PString bookMail
Mail to be used to contact authors in book mode.
bool isBibliography
True if the generated web site has a bibliography, false otherwise.
bool isRemoteMathjax
True to activate mathjax but in remote mode (so no need to have mathjax in the generated site)
PString currentStyle
Current style to be used for the generated pages of the site.

References POutoutMode::bookGitlabUrl, POutoutMode::bookMail, POutoutMode::bookMasterProjectUrl, POutoutMode::currentStyle, POutoutMode::isBibliography, POutoutMode::isBookTheme, POutoutMode::isMathJaxMode, POutoutMode::isRemoteMathjax, POutoutMode::mapVar, and platexobj_theme_set_var().

Referenced by processAllFile().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ platexobj_theme_set_var()

void platexobj_theme_set_var ( POutoutMode outputMode,
const PString varName,
const PString value 
)

Set a variable in the map of variable for theme (will take account the IS_XXX_BEGIN accordingly if the value is empty or not)

Parameters
[out]outputMode: POutoutMode to be updated
varName: name of the variable to be set
value: value of the variable to be set

Definition at line 184 of file platexobj_formulae.cpp.

184  {
185  outputMode.mapVar["${" + varName + "}"] = value;
186  if(value == ""){
187  outputMode.mapVar["${IS_" + varName + "_BEGIN}"] = "<!-- ";
188  outputMode.mapVar["${IS_" + varName + "_END}"] = " -->";
189  }else{
190  outputMode.mapVar["${IS_" + varName + "_BEGIN}"] = "";
191  outputMode.mapVar["${IS_" + varName + "_END}"] = "";
192  }
193 }

References POutoutMode::mapVar.

Referenced by platexobj_theme_init_var(), and platexobj_theme_update_var().

+ Here is the caller graph for this function:

◆ platexobj_theme_update_var()

void platexobj_theme_update_var ( POutoutMode outputMode,
const PString pageLink,
const PString pageTitle,
const PString prevSecLink,
const PString prevSecTitle,
const PString nextSecLink,
const PString nextSecTitle,
const PString parentSecLink,
const PString parentSecTitle,
const PPath currentSourceFile,
size_t  currentSourceLine 
)

Update var of POutoutMode for current section.

Parameters
[out]outputMode: POutoutMode to be modified
pageLink: link of the current page
pageTitle: title of the current page
prevSecLink: link of the previous section
prevSecTitle: title of the previous section
nextSecLink: link of the next section
nextSecTitle: title of the next section
parentSecLink: link of the parent section
parentSecTitle: title of the parent section
currentSourceFile: current source file of the section
currentSourceLine: current source line of the section

Definition at line 236 of file platexobj_formulae.cpp.

241 {
242  outputMode.mapVar["${PAGE_LINK}"] = pageLink;
243  outputMode.mapVar["${PAGE_TITLE}"] = pageTitle;
244  outputMode.mapVar["${PARENT_SECTION_TITLE}"] = parentSecTitle;
245  platexobj_theme_set_var(outputMode, "PARENT_SECTION", parentSecLink);
246  outputMode.mapVar["${PREV_PAGE_TITLE}"] = prevSecTitle;
247  platexobj_theme_set_var(outputMode, "PREV_PAGE", prevSecLink);
248  outputMode.mapVar["${NEXT_PAGE_TITLE}"] = nextSecTitle;
249  platexobj_theme_set_var(outputMode, "NEXT_PAGE", nextSecLink);
250 
251  outputMode.mapVar["${CURRENT_SOURCE_FILE}"] = currentSourceFile.makeAbsolute().simplify().getUnderPath(PPath(outputMode.bookGitlabUrl).getFileName());
252  outputMode.mapVar["${CURRENT_SOURCE_LINE}"] = valueToString(currentSourceLine);
253 
254 // outputMode.mapVar["${MAIN_TITLE}"] = "";
255 // outputMode.mapVar["${SUB_MENU}"] = "";
256 
257  if(outputMode.isBookTheme){
258  outputMode.mapVar["${BOOK_TABLE_OF_CONTENT}"] = platexobj_menuToHtml(outputMode.fullMenu, pageLink, outputMode.isBibliography);
259  }
260 }
Path of a directory or a file.
Definition: PPath.h:17
PPath getUnderPath(const PString &pathPart) const
Get path which is under the given pathPart ('some/dir/path' with 'dir' will return 'path')
Definition: PPath.cpp:360
PPath makeAbsolute() const
Make an absolute path of the given path.
Definition: PPath.cpp:572
PPath simplify() const
Remove extra dots from the path.
Definition: PPath.cpp:533
PPath getFileName() const
Get the name of the file, from last char to /.
Definition: PPath.cpp:172
std::string valueToString(const T &val)
Convert a type into a string.
PString platexobj_menuToHtml(const PFullMenu &menu, const PString &currentLink, bool isBibliography)
Convert a PFullMenu to html.
PFullMenu fullMenu
Full menu for book theme.

References POutoutMode::bookGitlabUrl, POutoutMode::fullMenu, PPath::getFileName(), PPath::getUnderPath(), POutoutMode::isBibliography, POutoutMode::isBookTheme, PPath::makeAbsolute(), POutoutMode::mapVar, platexobj_menuToHtml(), platexobj_theme_set_var(), PPath::simplify(), and valueToString().

Referenced by platexobj_book_createPage(), and platexobj_bookIndexHtml().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ platexobj_update_theme()

void platexobj_update_theme ( POutoutMode outputMode,
const PPath themeBaseFile 
)

Update the theme of the generated website.

Parameters
[out]outputMode: POutoutMode to be updated
themeBaseFile: file which contains the theme we want to use

Definition at line 175 of file platexobj_formulae.cpp.

175  {
176  dico_create_nested_call(outputMode.themeCall, themeBaseFile.loadFileContent(), "${", "}");
177 }
PString loadFileContent() const
Get the file content in a PString.
Definition: PPath.cpp:382
void dico_create_nested_call(PNestedCall &call, const PString &baseStr, const PString &varBegin, const PString &varEnd)
Create the nested calls of the input base string.

References dico_create_nested_call(), PPath::loadFileContent(), and POutoutMode::themeCall.

Referenced by processAllFile().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: