summaryrefslogtreecommitdiffstats
path: root/cli/generator.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'cli/generator.cxx')
-rw-r--r--cli/generator.cxx59
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)