1
/***************************************************************************
2
* Copyright (C) 2004-2009 by Thomas Fischer *
3
* fischer@unix-ag.uni-kl.de *
5
* This program is free software; you can redistribute it and/or modify *
6
* it under the terms of the GNU General Public License as published by *
7
* the Free Software Foundation; either version 2 of the License, or *
8
* (at your option) any later version. *
10
* This program is distributed in the hope that it will be useful, *
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13
* GNU General Public License for more details. *
15
* You should have received a copy of the GNU General Public License *
16
* along with this program; if not, write to the *
17
* Free Software Foundation, Inc., *
18
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19
***************************************************************************/
21
#include <QStringList>
22
#include <QTextStream>
25
#include <fileexporterbibtex.h>
26
#include "fileexporterps.h"
28
FileExporterPS::FileExporterPS()
29
: FileExporterToolchain(), m_latexLanguage("english"), m_latexBibStyle("plain")
31
m_laTeXFilename = tempDir.name() + QLatin1String("/bibtex-to-ps.tex");
32
m_bibTeXFilename = tempDir.name() + QLatin1String("/bibtex-to-ps.bib");
33
m_outputFilename = tempDir.name() + QLatin1String("/bibtex-to-ps.ps");
36
FileExporterPS::~FileExporterPS()
41
bool FileExporterPS::save(QIODevice* iodevice, const File* bibtexfile, QStringList *errorLog)
45
QFile output(m_bibTeXFilename);
46
if (output.open(QIODevice::WriteOnly)) {
47
FileExporter * bibtexExporter = new FileExporterBibTeX();
48
result = bibtexExporter->save(&output, bibtexfile, errorLog);
50
delete bibtexExporter;
54
result = generatePS(iodevice, errorLog);
59
bool FileExporterPS::save(QIODevice* iodevice, const Element* element, QStringList *errorLog)
63
QFile output(m_bibTeXFilename);
64
if (output.open(QIODevice::WriteOnly)) {
65
FileExporter * bibtexExporter = new FileExporterBibTeX();
66
result = bibtexExporter->save(&output, element, errorLog);
68
delete bibtexExporter;
72
result = generatePS(iodevice, errorLog);
77
void FileExporterPS::setLaTeXLanguage(const QString& language)
79
m_latexLanguage = language;
82
void FileExporterPS::setLaTeXBibliographyStyle(const QString& bibStyle)
84
m_latexBibStyle = bibStyle;
87
bool FileExporterPS::generatePS(QIODevice* iodevice, QStringList *errorLog)
89
QStringList cmdLines = QStringList() << QLatin1String("latex -halt-on-error bibtex-to-ps.tex") << QLatin1String("bibtex bibtex-to-ps") << QLatin1String("latex -halt-on-error bibtex-to-ps.tex") << QLatin1String("latex -halt-on-error bibtex-to-ps.tex") << QLatin1String("dvips -o bibtex-to-ps.ps bibtex-to-ps.dvi");
91
if (writeLatexFile(m_laTeXFilename) && runProcesses(cmdLines, errorLog) && writeFileToIODevice(m_outputFilename, iodevice))
97
bool FileExporterPS::writeLatexFile(const QString &filename)
99
QFile latexFile(filename);
100
if (latexFile.open(QIODevice::WriteOnly)) {
101
QTextStream ts(&latexFile);
102
ts.setCodec("UTF-8");
103
ts << "\\documentclass{article}\n";
104
if (kpsewhich("t2aenc.dfu") && kpsewhich("t1enc.dfu"))
105
ts << "\\usepackage[T1,T2A]{fontenc}\n";
106
ts << "\\usepackage[utf8]{inputenc}\n";
107
if (kpsewhich("babel.sty"))
108
ts << "\\usepackage[" << m_latexLanguage << "]{babel}\n";
109
if (kpsewhich("url.sty"))
110
ts << "\\usepackage{url}\n";
111
if (m_latexBibStyle.startsWith("apacite") && kpsewhich("apacite.sty"))
112
ts << "\\usepackage[bibnewpage]{apacite}\n";
113
ts << "\\bibliographystyle{" << m_latexBibStyle << "}\n";
114
ts << "\\begin{document}\n";
115
ts << "\\nocite{*}\n";
116
ts << "\\bibliography{bibtex-to-ps}\n";
117
ts << "\\end{document}\n";