@@ -60,13 +60,27 @@ void MainWindow::compile() {
6060 QSettings settings;
6161 QString program = settings.value (" compiler" , " pdflatex" ).toString ();
6262 QStringList arguments;
63+ QTemporaryDir tmpdir;
64+ tmpdir.setAutoRemove (true );
65+
6366 if (program == " pdflatex" ) {
6467 arguments << " -halt-on-error" ;
6568 }
66- arguments << " main.tex" ;
69+ if (dir->path () == " " ) {
70+ return ;
71+ }
72+ if (texdir.absolutePath () == " " ) {
73+ std::cout << " need a temporary directory" << std::endl;
74+ texdir = QFileInfo (tmpdir.path ());
75+ }
76+
77+ arguments << dir->filePath (" _livetikz_preview.tex" );
6778
79+ std::cout << " Arguments: " << dir->filePath (" _livetikz_preview.tex" ).toStdString () << std::endl;
80+ std::cout << " WD: " << texdir.absolutePath ().toStdString () << std::endl;
81+
6882 renderProcess = new QProcess (this );
69- renderProcess->setWorkingDirectory (dir-> path ());
83+ renderProcess->setWorkingDirectory (texdir. absolutePath ());
7084 renderProcess->start (program, arguments);
7185
7286 log->setText (" Compiling..." );
@@ -81,11 +95,13 @@ void MainWindow::compile() {
8195}
8296
8397void MainWindow::refresh () {
84- dir = new QTemporaryDir ();
85- dir->setAutoRemove (false );
98+ if (!dir) {
99+ dir = new QTemporaryDir ();
100+ dir->setAutoRemove (false );
101+ }
86102
87103 if (dir->isValid ()) {
88- QFile file (dir->path () + QString ( " /main .tex" ));
104+ QFile file (dir->filePath ( " _livetikz_preview .tex" ));
89105
90106 if (file.open (QIODevice::ReadWrite | QIODevice::Text)) {
91107 QTextStream out (&file);
@@ -163,9 +179,10 @@ void MainWindow::renderFinished(int code) {
163179 delete currentDoc;
164180 currentDoc = NULL ;
165181
166- QFile pdf_file (dir-> path ( ) + " /main .pdf" );
182+ QFile pdf_file (QDir::cleanPath (texdir. absolutePath ( ) + QDir::separator () + " _livetikz_preview .pdf" ) );
167183 if (pdf_file.exists ()) {
168- currentDoc = Poppler::Document::load (dir->path () + " /main.pdf" );
184+ QFile::rename (QDir::cleanPath (texdir.absolutePath () + QDir::separator () + " _livetikz_preview.pdf" ), dir->filePath (" _livetikz_preview.pdf" ));
185+ currentDoc = Poppler::Document::load (dir->filePath (" _livetikz_preview.pdf" ));
169186 if (currentDoc) {
170187 currentDoc->setRenderHint (Poppler::Document::TextAntialiasing);
171188 currentDoc->setRenderHint (Poppler::Document::Antialiasing);
@@ -192,6 +209,7 @@ MainWindow::MainWindow() : currentDoc(NULL), renderProcess(NULL), currentPage(0)
192209 setupMenu ();
193210 setupUI ();
194211
212+ dir = NULL ;
195213 templateFile = QUrl (settings.value (" template" , " " ).toString ());
196214 templateLabel->setText (templateFile.url (QUrl::PreferLocalFile));
197215
@@ -227,7 +245,10 @@ void MainWindow::showCompilerSelection() {
227245
228246MainWindow::~MainWindow () {}
229247
230- void MainWindow::load (const QUrl &url) { katePart->openUrl (url); }
248+ void MainWindow::load (const QUrl &url) {
249+ texdir = QFileInfo (url.toLocalFile ());
250+ katePart->openUrl (url);
251+ }
231252
232253void MainWindow::setupActions () {
233254 KStandardAction::open (this , SLOT (load ()), actionCollection ());
0 commit comments