From 7ba2bfb81d5318a010d2f3d34e084d8c68efd42d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Spitzm=C3=BCller?= Date: Fri, 22 May 2009 07:20:00 +0000 Subject: [PATCH] * Per-document setting for bibtex and makeindex. File format change. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@29774 a592a061-630c-0410-9148-cb99ea01b6c8 --- development/FORMAT | 17 ++- lib/lyx2lyx/lyx_2_0.py | 21 +++- src/Buffer.cpp | 2 +- src/BufferParams.cpp | 10 ++ src/BufferParams.h | 4 + src/Converter.cpp | 4 + src/LaTeX.cpp | 7 +- src/OutputParams.h | 8 ++ src/frontends/qt4/GuiDocument.cpp | 44 +++++++ src/frontends/qt4/GuiDocument.h | 1 + src/frontends/qt4/GuiIndices.cpp | 51 ++++++++ src/frontends/qt4/GuiIndices.h | 2 + src/frontends/qt4/ui/BiblioUi.ui | 159 ++++++++++++++++-------- src/frontends/qt4/ui/IndicesUi.ui | 196 ++++++++++++++++++++---------- 14 files changed, 403 insertions(+), 123 deletions(-) diff --git a/development/FORMAT b/development/FORMAT index 332d86feef..55faac5f4d 100644 --- a/development/FORMAT +++ b/development/FORMAT @@ -1,13 +1,17 @@ LyX file-format changes ----------------------- -2009-05-05 Pavel Sanda, Enrico Forestieri - * Format incremented to 357: Change of the latex output for underline - from \underbar to ulem's \uline. +2009-04-26 Jürgen Spitzmüller + * Format incremented to 358: support for custom bibtex and + makeindex commands. + +2009-05-05 Pavel Sanda , Enrico Forestieri + * Format incremented to 357: Change of the latex output for + underline from \underbar to ulem's \uline. 2009-05-05 Pavel Sanda - * Format incremented to 356: support for double and wave underline character - styles via ulem's \uuline and \uwave + * Format incremented to 356: support for double and wave underline + character styles via ulem's \uuline and \uwave 2009-05-03 Pavel Sanda * Format incremented to 355: support for strikeout character @@ -25,7 +29,8 @@ LyX file-format changes * Format incremented to 352: splitindex support. 2009-04-11 Uwe Stöhr - * Format incremented to 351: support to set a page background color. + * Format incremented to 351: support to set a page background + color. 2009-04-06 Jürgen Spitzmüller * Format incremented to 350: new param \default_output_format. diff --git a/lib/lyx2lyx/lyx_2_0.py b/lib/lyx2lyx/lyx_2_0.py index e021c2c662..ee508a23fc 100644 --- a/lib/lyx2lyx/lyx_2_0.py +++ b/lib/lyx2lyx/lyx_2_0.py @@ -630,6 +630,7 @@ def revert_uulinewave(document): return del document.body[i] + def revert_ulinelatex(document): " Reverts \\uline character style " i = find_token(document.body, '\\bar under', 0) @@ -645,6 +646,20 @@ def revert_ulinelatex(document): + '\\renewcommand{\\underbar}[1]{{\\let\\cite\\b@xcite\\uline{#1}}}\n') +def revert_custom_processors(document): + " Remove bibtex_command and index_command params " + i = find_token(document.header, '\\bibtex_command', 0) + if i == -1: + document.warning("Malformed LyX document: Missing \\bibtex_command.") + return + del document.header[i] + i = find_token(document.header, '\\index_command', 0) + if i == -1: + document.warning("Malformed LyX document: Missing \\index_command.") + return + del document.header[i] + + ## # Conversion hub # @@ -661,10 +676,12 @@ convert = [[346, []], [354, []], [355, []], [356, []], - [357, []] + [357, []], + [358, []] ] -revert = [[356, [revert_ulinelatex]], +revert = [[357, [revert_custom_processors]], + [356, [revert_ulinelatex]], [355, [revert_uulinewave]], [354, [revert_strikeout]], [353, [revert_printindexall]], diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 30076ff2f2..d557a21e73 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -125,7 +125,7 @@ namespace { // Do not remove the comment below, so we get merge conflict in // independent branches. Instead add your own. -int const LYX_FORMAT = 357; // sanda: change latex output for various underline commands +int const LYX_FORMAT = 358; // jspitzm: customizable bibtex/makeindex calls typedef map DepClean; typedef map > RefCache; diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp index f73942cd56..9aae6e7d2b 100644 --- a/src/BufferParams.cpp +++ b/src/BufferParams.cpp @@ -355,6 +355,8 @@ BufferParams::BufferParams() inputenc = "auto"; graphicsDriver = "default"; defaultOutputFormat = "default"; + bibtex_command = "default"; + index_command = "default"; sides = OneSide; columns = 1; listings_params = string(); @@ -531,6 +533,12 @@ string BufferParams::readToken(Lexer & lex, string const & token, readGraphicsDriver(lex); } else if (token == "\\default_output_format") { lex >> defaultOutputFormat; + } else if (token == "\\bibtex_command") { + lex.eatLine(); + bibtex_command = lex.getString(); + } else if (token == "\\index_command") { + lex.eatLine(); + index_command = lex.getString(); } else if (token == "\\font_roman") { lex.eatLine(); fontsRoman = lex.getString(); @@ -813,6 +821,8 @@ void BufferParams::writeFile(ostream & os) const } os << "\n\\graphics " << graphicsDriver << '\n'; os << "\\default_output_format " << defaultOutputFormat << '\n'; + os << "\\bibtex_command " << bibtex_command << '\n'; + os << "\\index_command " << index_command << '\n'; if (!float_placement.empty()) { os << "\\float_placement " << float_placement << '\n'; diff --git a/src/BufferParams.h b/src/BufferParams.h index 43beea44d4..d0888406f8 100644 --- a/src/BufferParams.h +++ b/src/BufferParams.h @@ -184,6 +184,10 @@ public: std::string graphicsDriver; /// The default output format std::string defaultOutputFormat; + /// customized bibliography processor + std::string bibtex_command; + /// customized index processor + std::string index_command; /// the rm font std::string fontsRoman; /// the sf font diff --git a/src/Converter.cpp b/src/Converter.cpp index 9b8a53df7e..9c905355c6 100644 --- a/src/Converter.cpp +++ b/src/Converter.cpp @@ -329,6 +329,10 @@ bool Converters::convert(Buffer const * buffer, if (buffer) { runparams.use_japanese = buffer->bufferFormat() == "platex"; runparams.use_indices = buffer->params().use_indices; + runparams.bibtex_command = (buffer->params().bibtex_command == "default") ? + string() : buffer->params().bibtex_command; + runparams.index_command = (buffer->params().index_command == "default") ? + string() : buffer->params().index_command; } // Some converters (e.g. lilypond) can only output files to the diff --git a/src/LaTeX.cpp b/src/LaTeX.cpp index f0a33ff8e7..658c5f5519 100644 --- a/src/LaTeX.cpp +++ b/src/LaTeX.cpp @@ -50,7 +50,6 @@ namespace os = support::os; // different way. // - the makeindex style files should be taken care of with // the dependency mechanism. -// - makeindex commandline options should be supported // - somewhere support viewing of bibtex and makeindex log files. // - we should perhaps also scan the bibtex log file @@ -414,6 +413,9 @@ bool LaTeX::runMakeIndex(string const & f, OutputParams const & runparams, { string tmp = runparams.use_japanese ? lyxrc.jindex_command : lyxrc.index_command; + + if (!runparams.index_command.empty()) + tmp = runparams.index_command; LYXERR(Debug::LATEX, "idx file has been made, running index processor (" @@ -570,6 +572,9 @@ bool LaTeX::runBibTeX(vector const & bibtex_info, string tmp = runparams.use_japanese ? lyxrc.jbibtex_command : lyxrc.bibtex_command; + + if (!runparams.bibtex_command.empty()) + tmp = runparams.bibtex_command; tmp += " "; // onlyFilename() is needed for cygwin tmp += quoteName(onlyFilename(removeExtension( diff --git a/src/OutputParams.h b/src/OutputParams.h index 9ead2167f7..75e6918089 100644 --- a/src/OutputParams.h +++ b/src/OutputParams.h @@ -127,6 +127,14 @@ public: */ bool use_japanese; + /** Customized bibtex_command + */ + mutable std::string bibtex_command; + + /** Customized index_command + */ + mutable std::string index_command; + /** Line length to use with plaintext export. */ size_type linelen; diff --git a/src/frontends/qt4/GuiDocument.cpp b/src/frontends/qt4/GuiDocument.cpp index 7753cc13f2..8e47d9ed24 100644 --- a/src/frontends/qt4/GuiDocument.cpp +++ b/src/frontends/qt4/GuiDocument.cpp @@ -859,10 +859,23 @@ GuiDocument::GuiDocument(GuiView & lv) this, SLOT(change_adaptor())); connect(biblioModule->bibtopicCB, SIGNAL(clicked()), this, SLOT(change_adaptor())); + connect(biblioModule->bibtexCO, SIGNAL(activated(int)), + this, SLOT(bibtexChanged(int))); + connect(biblioModule->bibtexOptionsED, SIGNAL(textChanged(QString)), + this, SLOT(change_adaptor())); // biblio biblioModule->citeStyleCO->addItem(qt_("Author-year")); biblioModule->citeStyleCO->addItem(qt_("Numerical")); biblioModule->citeStyleCO->setCurrentIndex(0); + + biblioModule->bibtexCO->clear(); + + biblioModule->bibtexCO->addItem(qt_("Default"), QString("default")); + for (vector::const_iterator it = lyxrc.bibtex_alternatives.begin(); + it != lyxrc.bibtex_alternatives.end(); ++it) { + QString const command = toqstr(*it).left(toqstr(*it).indexOf(" ")); + biblioModule->bibtexCO->addItem(command, command); + } // indices indicesModule = new GuiIndices; @@ -1498,6 +1511,13 @@ void GuiDocument::classChanged() } +void GuiDocument::bibtexChanged(int n) +{ + biblioModule->bibtexOptionsED->setEnabled(n != 0); + changed(); +} + + namespace { // This is an insanely complicated attempt to make this sort of thing // work with RTL languages. @@ -1721,6 +1741,15 @@ void GuiDocument::applyView() bp_.use_bibtopic = biblioModule->bibtopicCB->isChecked(); + string const bibtex_command = + fromqstr(biblioModule->bibtexCO->itemData( + biblioModule->bibtexCO->currentIndex()).toString()); + if (bibtex_command == "default") + bp_.bibtex_command = bibtex_command; + else + bp_.bibtex_command = bibtex_command + " " + + fromqstr(biblioModule->bibtexOptionsED->text()); + // Indices indicesModule->apply(bp_); @@ -2058,6 +2087,21 @@ void GuiDocument::paramsToDialog() biblioModule->bibtopicCB->setChecked( bp_.use_bibtopic); + string command; + string options = + split(bp_.bibtex_command, command, ' '); + + int const bpos = biblioModule->bibtexCO->findData(toqstr(command)); + if (bpos != -1) { + biblioModule->bibtexCO->setCurrentIndex(bpos); + biblioModule->bibtexOptionsED->setText(toqstr(options).trimmed()); + } else { + biblioModule->bibtexCO->setCurrentIndex(0); + biblioModule->bibtexOptionsED->clear(); + } + biblioModule->bibtexOptionsED->setEnabled( + biblioModule->bibtexCO->currentIndex() != 0); + // indices indicesModule->update(bp_); diff --git a/src/frontends/qt4/GuiDocument.h b/src/frontends/qt4/GuiDocument.h index e2075759c5..fa62c25496 100644 --- a/src/frontends/qt4/GuiDocument.h +++ b/src/frontends/qt4/GuiDocument.h @@ -99,6 +99,7 @@ private Q_SLOTS: void browseLayout(); void browseMaster(); void classChanged(); + void bibtexChanged(int); void updateModuleInfo(); void modulesChanged(); void changeBackgroundColor(); diff --git a/src/frontends/qt4/GuiIndices.cpp b/src/frontends/qt4/GuiIndices.cpp index fa8d6d8309..d44a377d13 100644 --- a/src/frontends/qt4/GuiIndices.cpp +++ b/src/frontends/qt4/GuiIndices.cpp @@ -22,6 +22,7 @@ #include "frontends/alert.h" #include "BufferParams.h" +#include "LyXRC.h" #include "support/gettext.h" #include "support/lstrings.h" @@ -34,6 +35,10 @@ #include +using namespace std; +using namespace lyx::support; + + namespace lyx { namespace frontend { @@ -46,6 +51,14 @@ GuiIndices::GuiIndices(QWidget * parent) indicesTW->headerItem()->setText(0, qt_("Name")); indicesTW->headerItem()->setText(1, qt_("Label Color")); indicesTW->setSortingEnabled(true); + + indexCO->clear(); + indexCO->addItem(qt_("Default"), QString("default")); + for (vector::const_iterator it = lyxrc.index_alternatives.begin(); + it != lyxrc.index_alternatives.end(); ++it) { + QString const command = toqstr(*it).left(toqstr(*it).indexOf(" ")); + indexCO->addItem(command, command); + } } void GuiIndices::update(BufferParams const & params) @@ -60,6 +73,22 @@ void GuiIndices::update(BufferParams const & params) availableLA->setEnabled(state); removePB->setEnabled(state); colorPB->setEnabled(state); + + string command; + string options = + split(params.index_command, command, ' '); + + int const pos = indexCO->findData(toqstr(command)); + if (pos != -1) { + indexCO->setCurrentIndex(pos); + indexOptionsED->setText(toqstr(options).trimmed()); + } else { + indexCO->setCurrentIndex(0); + indexOptionsED->clear(); + } + indexOptionsED->setEnabled( + indexCO->currentIndex() != 0); + updateView(); } @@ -103,6 +132,28 @@ void GuiIndices::apply(BufferParams & params) const { params.use_indices = multipleIndicesCB->isChecked(); params.indiceslist() = indiceslist_; + + string const index_command = + fromqstr(indexCO->itemData( + indexCO->currentIndex()).toString()); + if (index_command == "default") + params.index_command = index_command; + else + params.index_command = index_command + " " + + fromqstr(indexOptionsED->text()); +} + + +void GuiIndices::on_indexCO_activated(int n) +{ + indexOptionsED->setEnabled(n != 0); + changed(); +} + + +void GuiIndices::on_indexOptionsED_textChanged(QString) +{ + changed(); } diff --git a/src/frontends/qt4/GuiIndices.h b/src/frontends/qt4/GuiIndices.h index 87d946fa51..66cea923ef 100644 --- a/src/frontends/qt4/GuiIndices.h +++ b/src/frontends/qt4/GuiIndices.h @@ -44,6 +44,8 @@ protected: void updateView(); protected Q_SLOTS: + void on_indexCO_activated(int n); + void on_indexOptionsED_textChanged(QString); void on_addIndexPB_pressed(); void on_renamePB_clicked(); void on_removePB_pressed(); diff --git a/src/frontends/qt4/ui/BiblioUi.ui b/src/frontends/qt4/ui/BiblioUi.ui index 8435e1286a..2c87f799da 100644 --- a/src/frontends/qt4/ui/BiblioUi.ui +++ b/src/frontends/qt4/ui/BiblioUi.ui @@ -12,32 +12,23 @@ - - - 9 - - - 6 - + Citation Style - - - 9 - - - 6 - - - + + true + + + + - Use the jurabib styles for law and humanities + Use BibTeX's default numerical styles - &Jurabib + &Default (numerical) @@ -51,24 +42,14 @@ - - - - Use BibTeX's default numerical styles - - - &Default (numerical) - - - - - 0 - 6 + + 0 + @@ -88,9 +69,7 @@ false - - 0 - 0 + 0 0 @@ -99,23 +78,33 @@ + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Use the jurabib styles for law and humanities + + + &Jurabib + + + - - - - Qt::Horizontal - - - - 40 - 20 - - - - - + Select this if you want to split your bibliography into sections @@ -125,7 +114,77 @@ - + + + + Here you can define an alternative program to or specific options of bibtex. + + + Bibliography generation + + + true + + + + + + + + &Processor: + + + bibtexCO + + + + + + + Select a processor + + + + + + + + + Qt::Horizontal + + + + 183 + 20 + + + + + + + + + + &Options: + + + bibtexOptionsED + + + + + + + Define options such as --min-crossrefs (see man bibtex). + + + + + + + + + Qt::Vertical @@ -133,7 +192,7 @@ QSizePolicy::Expanding - + 20 20 diff --git a/src/frontends/qt4/ui/IndicesUi.ui b/src/frontends/qt4/ui/IndicesUi.ui index 1dcb47363a..62ea6a48a2 100644 --- a/src/frontends/qt4/ui/IndicesUi.ui +++ b/src/frontends/qt4/ui/IndicesUi.ui @@ -12,21 +12,102 @@ - - - 9 - - - 6 - - - - - 0 + + + + + Here you can define an alternative index processor and specify its options. + + Index generation + + + true + + + + + + + + &Processor: + + + indexCO + + + + + + + Select a processor + + + + + + + + + + + &Options: + + + indexOptionsED + + + + + + + Define program options of the selected processor. + + + + + + + + + Qt::Horizontal + + + + 183 + 20 + + + + + + + + + + + Check if you need multiple indexes (e.g., an Index of Names) + + + &Use multiple indexes + + + + + + + Qt::Horizontal + + + + + 6 + + 0 + @@ -56,33 +137,7 @@ - - - - Remove the selected index - - - &Remove - - - - - - - Qt::Vertical - - - QSizePolicy::Expanding - - - - 20 - 121 - - - - - + A&vailable Indexes: @@ -92,37 +147,26 @@ - - - - - - - Check if you need multiple indexes (e.g., an Index of Names) - - - &Use multiple indexes - + + + + + 1 + + - - - - Qt::Horizontal + + + + Remove the selected index + + + &Remove - - - Define or change button color - - - Alter Co&lor... - - - - Rename the selected index @@ -132,6 +176,32 @@ + + + + Define or change button color + + + Alter Co&lor... + + + + + + + Qt::Vertical + + + QSizePolicy::Expanding + + + + 20 + 121 + + + +