From 21b62e2ea5b1b04838878732a60d4692f20d51d3 Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Wed, 2 Jan 2019 12:51:32 +0100 Subject: allow custom tex code via .tikzdefs --- src/gui/latexprocess.cpp | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/gui/latexprocess.cpp b/src/gui/latexprocess.cpp index 0e2185a..992886e 100644 --- a/src/gui/latexprocess.cpp +++ b/src/gui/latexprocess.cpp @@ -67,11 +67,6 @@ void LatexProcess::makePreview(QString tikz) _output->appendPlainText("FOUND: " + pdflatex + "\n"); - // copy active *.tikzstyles file to preview dir - if (!tikzit->styleFile().isEmpty() && QFile::exists(tikzit->styleFilePath())) { - QFile::copy(tikzit->styleFilePath(), _workingDir.path() + "/" + tikzit->styleFile()); - } - // copy tikzit.sty to preview dir QFile::copy(":/tex/sample/tikzit.sty", _workingDir.path() + "/tikzit.sty"); @@ -83,7 +78,22 @@ void LatexProcess::makePreview(QString tikz) tex << "\\usepackage{tikzit}\n"; tex << "\\usepackage[graphics,active,tightpage]{preview}\n"; tex << "\\PreviewEnvironment{tikzpicture}\n"; - tex << "\\input{" + tikzit->styleFile() + "}\n"; + + // copy active *.tikzstyles file to preview dir + if (!tikzit->styleFile().isEmpty() && QFile::exists(tikzit->styleFilePath())) { + QFile::copy(tikzit->styleFilePath(), _workingDir.path() + "/" + tikzit->styleFile()); + tex << "\\input{" + tikzit->styleFile() + "}\n"; + + // if there is a *.tikzdefs file with the same basename, copy and include it as well + QFileInfo fi(tikzit->styleFilePath()); + QString defFile = fi.baseName() + ".tikzdefs"; + QString defFilePath = fi.absolutePath() + "/" + defFile; + if (QFile::exists(defFilePath)) { + QFile::copy(defFilePath, _workingDir.path() + "/" + defFile); + tex << "\\input{" + defFile + "}\n"; + } + } + tex << "\\begin{document}\n\n"; tex << tikz; tex << "\n\n\\end{document}\n"; -- cgit v1.2.3