PhoenixLecture  2.0.0
Set of tools to make lectures
main.cpp
Go to the documentation of this file.
1 /***************************************
2  Auteur : Pierre Aubert
3  Mail : pierre.aubert@lapp.in2p3.fr
4  Licence : CeCILL-C
5 ****************************************/
6 
7 #include "phoenix_system.h"
8 #include "OptionParser.h"
9 
19 #include "PLatexObj/updateMenu.h"
21 #include "PLatexObj/updateParent.h"
22 #include "PLatexObj/update_wip.h"
28 #include "PConfigParser.h"
29 #include "PMarkdownParser.h"
30 
32 struct ParsedArg{
34  bool useMathJax;
49 };
50 
52 
55  arg.useMathJax = false;
56  arg.useRemoteMathjax = false;
58  arg.isWorkInProgress = false;
59  arg.isLatexBackEnd = false;
60  arg.isBookTheme = false;
61  arg.styleCss = "";
62  arg.themeFile = PPath::getProgramPrefix() + "/share/PhoenixTex2Html/THEME/default.html";
63 }
64 
66 
69  OptionParser parser(true, __PROGRAM_VERSION__);
70  parser.setExampleLongOption("phoenix_tex2html --input=fileInput.tex --output=\"output/Directory\"");
71  parser.setExampleShortOption("phoenix_tex2html -i fileInput.tex -o output/Directory");
72 
73  parser.addOption("input", "i", OptionType::FILENAME, true, "name of the input file");
74 
75  PString bibliographyFile("");
76  parser.addOption("bibliography", "b", bibliographyFile, "input bibliography file");
77  PString includeDir(".");
78  parser.addOption("includedirs", "I", includeDir, "list of include directories");
79 
80  PString defaultStyle("base");
81  parser.addOption("style", "s", defaultStyle, "set the default style to be used (base, dark)");
82 
83  parser.addOption("workinprogress", "w", OptionType::NONE, false, "propagates the Work In Progress in the titles of corresponding parts, to make them visible and see what is ongoing in an easier way");
84  parser.addOption("mathjax", "j", OptionType::NONE, false, "enable the MathJax backend instead of the Latex one");
85  parser.addOption("remotemathjax", "r", OptionType::NONE, false, "enable the MathJax backend, with remote install, instead of the Latex one");
86 
87  parser.addOption("tex", "t", OptionType::NONE, false, "enable the latex backend. All input will be converted into latex files");
88  parser.addOption("book", "k", OptionType::NONE, false, "enable the book theme");
89 
90  PString installPrefix(PPath::getProgramPrefix());
91  parser.addOption("prefix", "p", installPrefix, "Installation prefix directory (/usr or /local/usr to get shared files");
92  PString defaultTheme(PPath::getProgramPrefix() + "/share/PhoenixTex2Html/THEME/default.html");
93  parser.addOption("theme", "a", defaultTheme, "base theme to be used as canevas to all generated web pages");
94  return parser;
95 }
96 
98 
103 template<typename T>
104 int processAllFile(const PPath & fileinput, const PPath & inputBibliography,
105  const PVecString & listInclude, const ParsedArg & arg)
106 {
107  if(fileinput == "") return 0;
108 
109  T parser(arg.installPrefix);
110  parser.setDebugMode(true);
111  bool isBibliography(inputBibliography != "");
112  if(isBibliography){
113  PMapBiblioEntry & mapBibio = parser.getMapBiblioEntry();
114  if(!pbliblio_file(mapBibio, inputBibliography)){
115  std::cerr << "processAllFile : can't parse the bibliography file '"<<inputBibliography<<"'" << std::endl;
116  return -1;
117  }
118  std::cout << "Find " << mapBibio.size() << " entries in the bibliography" << std::endl;
119  }
120 
121  for(PVecString::const_iterator it(listInclude.begin()); it != listInclude.end(); ++it){
122  parser.getVecIncludeDir().push_back(*it);
123  }
124  if(!parser.saveCss()){
125  std::cerr << "processAllFile : can't save css file" << std::endl;
126  return -1;
127  }
128  if(!parser.load(fileinput)){
129  std::cerr << "processAllFile : can't load file '"<<fileinput<<"'" << std::endl;
130  return -1;
131  }
132  PLatexObj latexFile(parser.getSource());
133  PString firstStyleCss(arg.styleCss);
134  update_firstCss(firstStyleCss, latexFile);
135  platexobj_updateId(latexFile);
136 
137  PLatexObj orderLatex(platexobj_order(latexFile));
138  platexobj_updateNumber(orderLatex);
139 
140  platexobj_updateFileName(orderLatex);
141  platexobj_updateLink(orderLatex);
142 
143  updateFigureNumber(orderLatex);
144  updateLabelRef(orderLatex);
145  if(isBibliography){
146  PMapBiblioEntry & mapBibio = parser.getMapBiblioEntry();
147  updateLabelCitation(orderLatex, mapBibio);
148  }
149  POutoutMode outputMode;
150  outputMode.currentStyle = firstStyleCss;
151  outputMode.isMathJaxMode = arg.useMathJax;
152  outputMode.isRemoteMathjax = arg.useRemoteMathjax;
153  outputMode.isBibliography = isBibliography;
155 
156  if(arg.isWorkInProgress && !arg.isLatexBackEnd){
157  updateWip(orderLatex);
158  }
159 
160  updateMenu(outputMode, orderLatex);
161  updateNextPrev(outputMode, orderLatex);
162  updateParent(outputMode, orderLatex);
163  updateNewLine(orderLatex);
164  outputMode.isBookTheme = arg.isBookTheme;
165  platexobj_update_theme(outputMode, arg.themeFile);
166  if(arg.isBookTheme){
167  std::cout << "processAllFile : book mode enabled" << std::endl;
168  outputMode.fullMenu = platexobj_toMenu(orderLatex, parser.getBookMainPageLink());
169 
170  outputMode.bookSideBarWidth = parser.getBookSideBarWidth();
171  outputMode.bookGitlabUrl = parser.getBookGitlabUrl();
172  outputMode.isEnableBookFeedback = parser.getBookEnableFeedback();
173  outputMode.bookMail = parser.getBookMail();
174  outputMode.bookMasterProjectUrl = parser.getBookMasterProjectUrl();
175 
176  }
177  if(isBibliography && !arg.isLatexBackEnd){ //Save the bibliography if there is one
178  PMapBiblioEntry & mapBibio = parser.getMapBiblioEntry();
179  if(!pbiblio_html(PPath("bibliography.html"), mapBibio, outputMode)){
180  std::cerr << "processAllFile : can't save bibliography" << std::endl;
181  return -1;
182  }
183  }
184  if(arg.isLatexBackEnd){
185  POutputTex outputTexMode(defaultPOutputTex());
186  orderLatex.setLink("index.tex");
187  if(!platexobj_tex(outputTexMode, orderLatex)){ //Save the html pages
188  std::cerr << "processAllFile : can't save file in latex" << std::endl;
189  return -1;
190  }
191  }else{
192  platexobj_theme_init_var(outputMode); //Init theme basic variables
193  if(!platexobj_html(outputMode, orderLatex, isBibliography, arg.installPrefix)){ //Save the html pages
194  std::cerr << "processAllFile : can't files 'save html'" << std::endl;
195  return -1;
196  }
197  if(!arg.isBookTheme){
198  if(!createOutlineHtml(outputMode, orderLatex, isBibliography)){ //Save the outline
199  std::cerr << "processAllFile : can't save file 'outline.html'" << std::endl;
200  return -1;
201  }
202  }
204  }
205  return 0;
206 }
207 
208 int main(int argc, char** argv){
209  OptionParser parser = createOptionParser();
210  parser.parseArgument(argc, argv);
211 
212  const OptionMode & defaultMode = parser.getDefaultMode();
213  PPath inputFile;
214  defaultMode.getValue(inputFile, "input");
215 
216  PString inputBibliography("");
217  defaultMode.getValue(inputBibliography, "bibliography");
218 
219  PVecString listInclude;
220  defaultMode.getValue(listInclude, "includedirs");
221 
222  ParsedArg arg;
223  defaultParsedArg(arg);
224 
225  defaultMode.getValue(arg.styleCss, "style");
226 
227  arg.useMathJax = defaultMode.isOptionExist("mathjax");
228  arg.useRemoteMathjax = defaultMode.isOptionExist("remotemathjax");
229  arg.useMathJax |= arg.useRemoteMathjax;
230  arg.isWorkInProgress = defaultMode.isOptionExist("workinprogress");
231  arg.isLatexBackEnd = defaultMode.isOptionExist("tex");
232  arg.isBookTheme = defaultMode.isOptionExist("book");
233  defaultMode.getValue(arg.installPrefix, "prefix");
234  defaultMode.getValue(arg.themeFile, "theme");
235  if(arg.isBookTheme){
236  arg.themeFile = PPath::getProgramPrefix() + "/share/PhoenixTex2Html/THEME/book.html";
237  }
238 
239  PString fileExtention(inputFile.getExtension());
240  if(fileExtention == "md"){
241  return processAllFile<PMarkdownParser>(inputFile, inputBibliography, listInclude, arg);
242  }else if(fileExtention == "tex" || fileExtention == "ptex"){
243  return processAllFile<PConfigParser>(inputFile, inputBibliography, listInclude, arg);
244  }else{
245  std::cerr << "phoenix_tex2html : Unknow file extention '"<<fileExtention<<"' of input file '"<<inputFile<<"'" << std::endl;
246  return -1;
247  }
248 }
249 
250 
251 
std::vector< PString > PVecString
Definition: PString.h:96
int main(int argc, char **argv)
Definition: main.cpp:228
OptionParser createOptionParser()
Create the OptionParser of this program.
Definition: main.cpp:17
void defaultParsedArg(ParsedArg &arg)
Init default values in the ParsedArg.
Definition: main.cpp:54
int processAllFile(const PPath &fileinput, const PPath &inputBibliography, const PVecString &listInclude, const ParsedArg &arg)
Process all the input files.
Definition: main.cpp:104
Describe a mode in the program arguments.
Definition: OptionMode.h:13
bool isOptionExist(const PString &optionName) const
Say if the given option has been passed to the program.
Definition: OptionMode.cpp:210
bool getValue(T &value, const PString &optionName) const
Get the value of the option.
Parse the options passed to a program.
Definition: OptionParser.h:15
void parseArgument(int argc, char **argv)
Parse the arguments passed to the program.
void addOption(const PString &longOption, const PString &shortOption, OptionType::OptionType optionType, bool isRequired, const PString &docString)
Add an option in the OptionParser.
void setExampleShortOption(const PString &example)
Set the example usage of the program.
void setExampleLongOption(const PString &example)
Set the example usage of the program.
const OptionMode & getDefaultMode() const
Get default mode.
Describe a latex object.
Definition: PLatexObj.h:40
void setLink(const PString &link)
Sets the link of the PLatexObj.
Definition: PLatexObj.cpp:165
Path of a directory or a file.
Definition: PPath.h:17
PString getExtension() const
Get file extension.
Definition: PPath.cpp:252
static PPath getProgramPrefix()
Get the program prefix (installation directory without /bin)
Definition: PPath.cpp:622
Extends the std::string.
Definition: PString.h:16
bool createOutlineHtml(POutoutMode &outputMode, const PLatexObj &obj, bool isBibliography)
Create the outline.
PString pbiblio_html(const PMapBiblioEntry &mapBiblioEntry, const POutoutMode &outputMode)
Save the bibliography in string.
bool pbliblio_file(PMapBiblioEntry &mapBiblioEntry, const PPath &fileName)
Parse the full bibliography file.
std::map< PString, PBiblioEntry > PMapBiblioEntry
Describes the map for all PBiblioEntry.
void platexobj_theme_init_var(POutoutMode &outputMode)
Initialise basic variables of POutoutMode.
void platexobj_loadFormulaeMap(PMapFormula &mapFormula)
Load the map file of all the formulae if it exists.
void platexobj_update_theme(POutoutMode &outputMode, const PPath &themeBaseFile)
Update the theme of the generated website.
void platexobj_saveFormulaeMap(const PMapFormula &mapFormula)
Save the map file of the formulae to avoid extra latex call.
bool platexobj_html(POutoutMode &outputMode, const PLatexObj &obj, bool isBibliography=false, const PString &baseInstallPrefix="")
PFullMenu platexobj_toMenu(const PLatexObj &obj, const PLatexObj &mainPageLink)
Convert a PLatexObj into a menu.
PLatexObj platexobj_order(PLatexObj &obj)
Order the PLatexObj in part,chapter,section,subsection,subsubsection.
bool platexobj_tex(POutputTex &outputMode, const PLatexObj &obj)
Save the main PLatexObj.
POutputTex defaultPOutputTex()
Create a default POutputTex.
void platexobj_updateLink(PLatexObj &obj, const PPath &htmlFile)
Update the html link.
void platexobj_updateFileName(PLatexObj &obj)
Update the fileName of the PLatexObj part,chapter,section,subsection,subsubsection.
void platexobj_updateId(PLatexObj &obj, long unsigned int &id)
Update the id of the PLatexObj.
void platexobj_updateNumber(PLatexObj &obj, PVecNumber &vecNumber)
Update the vector number of the PLatexObj.
Output mode of the html backend.
bool isEnableBookFeedback
True to enable feedback in book mode.
bool isMathJaxMode
True to use the MathJax backend, false to use the latex backend.
PFullMenu fullMenu
Full menu for book theme.
PString bookGitlabUrl
Gitlab url of the current sources of the project.
PMapFormula mapFormula
Map of the formula which are already saved as png files.
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.
PString bookSideBarWidth
Witdh of the book side bar.
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.
Output mode for tex backend.
Definition: platexobj_tex.h:13
Parsed arguments passed to the program.
Definition: main.cpp:32
bool isWorkInProgress
True to propagate the Work In Progress in the titles of corresponding parts, to make them visible and...
Definition: main.cpp:40
PString themeFile
File which describes the theme of the web site.
Definition: main.cpp:48
bool useRemoteMathjax
True to use remote install of mathjax.
Definition: main.cpp:36
PString styleCss
Style to be used as the default css style.
Definition: main.cpp:46
bool isBookTheme
True to enable book theme.
Definition: main.cpp:44
bool useMathJax
True to use the MathJax backend, false to use the latex backend.
Definition: main.cpp:34
PString installPrefix
Installation prefix directory to get the program ressources (/usr or /local/usr)
Definition: main.cpp:38
bool isLatexBackEnd
True to activate the latex backend.
Definition: main.cpp:42
void updateFigureNumber(PLatexObj &obj)
Update all the figure number of the given PLatexObj.
void updateLabelCitation(PLatexObj &obj, const PMapBiblioEntry &mapBiblioEntry)
Update the label of the references.
void updateLabelRef(PLatexObj &obj)
Update the label of the references.
void updateMenu(POutoutMode &outputMode, PLatexObj &obj)
Update the menu of the latex obj.
Definition: updateMenu.cpp:14
void updateNextPrev(POutoutMode &outputMode, PLatexObj &obj, PLatexObj *&lastSec)
Update the next and previous section for the menu.
void updateParent(POutoutMode &outputMode, PLatexObj &obj, const PLatexMenu &parentMenu)
Update the parent of the sections.
void update_firstCss(PString &firstCss, const PLatexObj &source)
Update the firstCss style to be used.
void updateNewLine(PLatexObj &obj)
Update the new lines to ensure there are new two following.
void updateWip(PLatexObj &obj)
Update the Part/Chapter/Section/etc if they contains a work in progress.
Definition: update_wip.cpp:59