1
/***************************************************************************
2
* Copyright (C) 2004-2010 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>
23
#include <QTextStream>
30
#include <fileexporterbibtex.h>
31
#include "fileexporterblg.h"
33
FileExporterBLG::FileExporterBLG()
34
: FileExporterToolchain(), m_latexLanguage("english"), m_latexBibStyle("plain")
36
m_laTeXFilename = tempDir.name() + QLatin1String("/bibtex-to-blg.tex");
37
m_bibTeXFilename = tempDir.name() + QLatin1String("/bibtex-to-blg.bib");
40
FileExporterBLG::~FileExporterBLG()
45
bool FileExporterBLG::save(QIODevice*ioDevice, const File* bibtexfile, QStringList *errorLog)
49
QFile output(m_bibTeXFilename);
50
if (output.open(QIODevice::WriteOnly)) {
51
FileExporter* bibtexExporter = new FileExporterBibTeX();
52
result = bibtexExporter->save(&output, bibtexfile, errorLog);
53
bibtexExporter->save(ioDevice, bibtexfile, NULL);
55
delete bibtexExporter;
59
result = generateBLG(errorLog);
64
bool FileExporterBLG::save(QIODevice *ioDevice, const Element* element, QStringList *errorLog)
68
QFile output(m_bibTeXFilename);
69
if (output.open(QIODevice::WriteOnly)) {
70
FileExporter * bibtexExporter = new FileExporterBibTeX();
71
result = bibtexExporter->save(&output, element, errorLog);
72
bibtexExporter->save(ioDevice, element, NULL);
74
delete bibtexExporter;
78
result = generateBLG(errorLog);
83
void FileExporterBLG::setLaTeXLanguage(const QString& language)
85
m_latexLanguage = language;
88
void FileExporterBLG::setLaTeXBibliographyStyle(const QString& bibStyle)
90
m_latexBibStyle = bibStyle;
93
bool FileExporterBLG::generateBLG(QStringList *errorLog)
95
QStringList cmdLines = QStringList() << QLatin1String("pdflatex -halt-on-error bibtex-to-blg.tex") << QLatin1String("bibtex bibtex-to-blg");
97
if (writeLatexFile(m_laTeXFilename) && runProcesses(cmdLines, errorLog))
100
kWarning() << "Generating BLG failed";
105
bool FileExporterBLG::writeLatexFile(const QString &filename)
107
QFile latexFile(filename);
108
if (latexFile.open(QIODevice::WriteOnly)) {
109
QTextStream ts(&latexFile);
110
ts.setCodec("UTF-8");
111
ts << "\\documentclass{article}\n";
112
ts << "\\usepackage[T1]{fontenc}\n";
113
ts << "\\usepackage[utf8]{inputenc}\n";
114
ts << "\\usepackage[" << m_latexLanguage << "]{babel}\n";
115
if (kpsewhich("hyperref.sty"))
116
ts << "\\usepackage[pdfproducer={KBibTeX: http://home.gna.org/kbibtex/},pdftex]{hyperref}\n";
117
else if (kpsewhich("url.sty"))
118
ts << "\\usepackage{url}\n";
119
if (m_latexBibStyle.startsWith("apacite") && kpsewhich("apacite.sty"))
120
ts << "\\usepackage[bibnewpage]{apacite}\n";
121
ts << "\\bibliographystyle{" << m_latexBibStyle << "}\n";
122
ts << "\\begin{document}\n";
123
ts << "\\nocite{*}\n";
124
ts << "\\bibliography{bibtex-to-blg}\n";
125
ts << "\\end{document}\n";