diff options
author | Matthew Krupcale <mkrupcale@matthewkrupcale.com> | 2019-03-09 21:23:02 -0500 |
---|---|---|
committer | Matthew Krupcale <mkrupcale@matthewkrupcale.com> | 2019-03-14 14:53:02 -0400 |
commit | eb6df5fd19436dfff69c433befca47c47067b909 (patch) | |
tree | a73aa7d20e118678c913d2d08f0c21d2bcbea3ae /cli/generator.cxx | |
parent | 7d02451df7a97a03ed010cd324178a666f9ccd7a (diff) | |
download | cli-eb6df5fd19436dfff69c433befca47c47067b909.tar.gz cli-eb6df5fd19436dfff69c433befca47c47067b909.tar.xz cli-eb6df5fd19436dfff69c433befca47c47067b909.zip |
Add support for LaTeX output.generate-latex
* cli/content.cxx: Handle LaTeX generation in format_line and format for escaped and un-escaped CLI translated input.
* cli/context.hxx: Add ot_latex to output_type enum.
* cli/generator.cxx: Include LaTeX output if gen_latex is specified.
* cli/latex.{cxx,hxx}: LaTeX output generation: LaTeX escapes, line-wrapping, and doc, option, class_ traversal
* cli/options.{cli,cxx,hxx,ixx}: Add LaTeX generation options
Diffstat (limited to 'cli/generator.cxx')
-rw-r--r-- | cli/generator.cxx | 59 |
1 files changed, 55 insertions, 4 deletions
diff --git a/cli/generator.cxx b/cli/generator.cxx index 33f3b46..b27a936 100644 --- a/cli/generator.cxx +++ b/cli/generator.cxx @@ -23,6 +23,7 @@ #include <cli/man.hxx> #include <cli/html.hxx> +#include <cli/latex.hxx> #include <cli/txt.hxx> #include <cli/context.hxx> @@ -146,9 +147,10 @@ generate (options& ops, semantics::cli_unit& unit, path const& p) bool gen_cxx (ops.generate_cxx ()); bool gen_man (ops.generate_man ()); bool gen_html (ops.generate_html ()); + bool gen_latex (ops.generate_latex ()); bool gen_txt (ops.generate_txt ()); - if (!gen_cxx && !gen_man && !gen_html && !gen_txt) + if (!gen_cxx && !gen_man && !gen_html && !gen_latex && !gen_txt) gen_cxx = true; if (ops.stdout_ ()) @@ -159,9 +161,9 @@ generate (options& ops, semantics::cli_unit& unit, path const& p) throw failed (); } - if ((gen_man && gen_html) || - (gen_man && gen_txt) || - (gen_html && gen_txt)) + if ((gen_man && (gen_html || gen_latex || gen_txt)) || + (gen_html && (gen_latex || gen_txt)) || + (gen_latex && gen_txt)) { cerr << "error: --stdout cannot only be used with one output format" << endl; @@ -516,6 +518,55 @@ generate (options& ops, semantics::cli_unit& unit, path const& p) ctx.verify_id_ref (); } + // LaTeX output + // + if (gen_latex) + { + ofstream latex; + + if (!ops.stdout_ ()) + { + // May have to update link derivation in format_line() if changing + // this. + // + path latex_path (pfx + base + sfx + ops.latex_suffix ()); + + if (!ops.output_dir ().empty ()) + latex_path = path (ops.output_dir ()) / latex_path; + + latex.open (latex_path.string ().c_str ()); + + if (!latex.is_open ()) + { + cerr << "error: unable to open '" << latex_path << "' in write mode" + << endl; + throw failed (); + } + + auto_rm.add (latex_path); + } + + // The explicit cast helps VC++ 8.0 overcome its issues. + // + ostream& os (ops.stdout_ () ? cout : static_cast<ostream&> (latex)); + context ctx (os, context::ot_latex, unit, ops); + + for (bool first (true); first || ctx.toc; first = false) + { + append (ctx, ops.latex_prologue (), ops.latex_prologue_file ()); + generate_latex (ctx); + append (ctx, ops.latex_epilogue (), ops.latex_epilogue_file ()); + + if (ctx.toc) + { + assert (first); // Second run should end in non-TOC mode. + ctx.toc++; // TOC phase after restart. + } + } + + ctx.verify_id_ref (); + } + // txt output // if (gen_txt) |