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 ++++++++++++++++------ tex/sample/figures/fig.tikz | 2 +- tex/sample/sample.tex | 2 +- tex/sample/sample.tikzdefs | 6 ++++++ tex/sample/sample.tikzstyles | 6 +++--- 5 files changed, 27 insertions(+), 11 deletions(-) create mode 100644 tex/sample/sample.tikzdefs 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"; diff --git a/tex/sample/figures/fig.tikz b/tex/sample/figures/fig.tikz index b7074a8..f454de2 100644 --- a/tex/sample/figures/fig.tikz +++ b/tex/sample/figures/fig.tikz @@ -3,7 +3,7 @@ \node [style=red node] (0) at (0, 1) {}; \node [style=blue node 2] (1) at (1, 0) {}; \node [style=blue node] (2) at (-1, 0) {}; - \node [style=yellow square] (3) at (0, -1) {foo}; + \node [style=yellow square] (3) at (0, -1) {\anglevec{\alpha}}; \end{pgfonlayer} \begin{pgfonlayer}{edgelayer} \draw [in=-90, out=0] (3) to (1); diff --git a/tex/sample/sample.tex b/tex/sample/sample.tex index 1b10cf6..c6fb3ca 100644 --- a/tex/sample/sample.tex +++ b/tex/sample/sample.tex @@ -1,7 +1,7 @@ \documentclass{article} \usepackage{tikzit} \input{sample.tikzstyles} - +\input{sample.tikzdefs} \begin{document} diff --git a/tex/sample/sample.tikzdefs b/tex/sample/sample.tikzdefs new file mode 100644 index 0000000..ac25b5a --- /dev/null +++ b/tex/sample/sample.tikzdefs @@ -0,0 +1,6 @@ +% Optional: use this file for definitions that should be used by TikZiT to generate +% LaTeX preview. It can also be included in the paper. + +\usepackage{bm} + +\newcommand{\anglevec}[1]{\ensuremath{\vec{\bm{#1}}}} diff --git a/tex/sample/sample.tikzstyles b/tex/sample/sample.tikzstyles index df70248..5790de1 100644 --- a/tex/sample/sample.tikzstyles +++ b/tex/sample/sample.tikzstyles @@ -4,9 +4,9 @@ % \tikzstyle{NAME}=[PROPERTY LIST] % Node styles -\tikzstyle{red node}=[fill=red, tikzit category=nodes] -\tikzstyle{blue node}=[fill=blue] -\tikzstyle{blue node 2}=[tikzit fill=green, fill=blue] +\tikzstyle{red node}=[fill=red, tikzit category=nodes, shape=circle, draw=black] +\tikzstyle{blue node}=[fill=blue, shape=circle, draw=black] +\tikzstyle{blue node 2}=[tikzit fill=green, fill=blue, shape=circle, draw=black] \tikzstyle{yellow square}=[draw=black, fill=yellow, shape=rectangle] % Edge styles -- cgit v1.2.3