1 #include "export-latex.h"
3 #include "mainwindow.h"
6 extern Main *mainWindow;
7 extern Settings settings;
9 ExportLaTeX::ExportLaTeX()
12 filter = "LaTeX files (*.tex);;All (* *.*)";
14 // Note: key in hash on left side is the regular expression, which
15 // will be replaced by string on right side
16 // E.g. a literal $ will be replaced by \$
28 QString ExportLaTeX::escapeLaTeX(const QString &s)
35 foreach (QString p, esc.keys()) {
37 r.replace(rx, esc[p]);
42 void ExportLaTeX::doExport()
44 // Exports a map to a LaTex file.
45 // This file needs to be included
46 // or inported into a LaTex document
47 // it will not add a preamble, or anything
48 // that makes a full LaTex document.
50 if (!file.open(QIODevice::WriteOnly)) {
51 QMessageBox::critical(
52 0, QObject::tr("Critical Export Error"),
53 QObject::tr("Could not export as LaTeX to %1").arg(filePath));
54 mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
58 // Read default section names
59 QStringList sectionNames;
67 for (int i = 0; i < 6; i++)
70 .value(QString("/export/latex/sectionName-%1").arg(i),
76 // Main loop over all branches
78 BranchItem *cur = NULL;
79 BranchItem *prev = NULL;
80 model->nextBranch(cur, prev);
82 if (!cur->hasHiddenExportParent()) {
84 s = escapeLaTeX(cur->getHeadingPlain());
85 if (sectionNames.at(d).isEmpty() || d >= sectionNames.count())
89 out += "\\" + sectionNames.at(d) + "{" + s + "}";
92 // If necessary, write note
93 if (!cur->isNoteEmpty()) {
94 out += (cur->getNoteASCII());
98 model->nextBranch(cur, prev);
101 QTextStream ts(&file);
102 ts.setCodec("UTF-8");
106 QClipboard *clipboard = QGuiApplication::clipboard();
107 clipboard->setText(out);
109 result = ExportBase::Success;
111 displayedDestination = filePath;