From f3e0d5b9dabaf9fa2e05469cd42836477de08de4 Mon Sep 17 00:00:00 2001 From: albert-github Date: Fri, 4 Jan 2019 15:45:50 +0100 Subject: [PATCH] issue #6733 invalid cite anchor id when using crossref The crossreference possibility was not properly taken into account in bibtex conversion for other formats than LaTeX. - doxygen.bst: use correct labels (i.e. add 'CITEREF_' in case of crossreferences to the giver name) - cite.cpp: add the crossreferences to the citation dictionary (to overcome warning message). - extending test 012 --- src/cite.cpp | 61 +++++++++++++++++++++++++++++++---- templates/html/doxygen.bst | 12 +++---- testing/012/citelist.xml | 65 +++++++++++++++++++++++++------------- testing/012/indexpage.xml | 25 ++++++++------- testing/012_cite.dox | 2 ++ testing/sample.bib | 25 +++++++++++++++ 6 files changed, 143 insertions(+), 47 deletions(-) mode change 100644 => 100755 testing/012/citelist.xml mode change 100644 => 100755 testing/012/indexpage.xml diff --git a/src/cite.cpp b/src/cite.cpp index 4f886119e92..fd7b0e4544d 100644 --- a/src/cite.cpp +++ b/src/cite.cpp @@ -22,11 +22,13 @@ #include "language.h" #include "ftextstream.h" #include "resourcemgr.h" +#include "doxygen.h" #include //-------------------------------------------------------------------------- const QCString CiteConsts::fileName("citelist"); +/* when changing this also take doxygen.bst into account */ const QCString CiteConsts::anchorPrefix("CITEREF_"); const QCString bibTmpFile("bibTmpFile_"); const QCString bibTmpDir("bibTmpDir/"); @@ -118,8 +120,58 @@ void CiteDict::generatePage() const // do not generate an empty citations page if (isEmpty()) return; // nothing to cite - // 1. generate file with markers and citations to OUTPUT_DIRECTORY + // 0. add cross references from the bib files to the cite dictionary QFile f; + QStrList &citeDataList = Config_getList(CITE_BIB_FILES); + const char *bibdata = citeDataList.first(); + while (bibdata) + { + QCString bibFile = bibdata; + if (!bibFile.isEmpty() && bibFile.right(4)!=".bib") bibFile+=".bib"; + QFileInfo fi(bibFile); + if (fi.exists()) + { + if (!bibFile.isEmpty()) + { + f.setName(bibFile); + if (!f.open(IO_ReadOnly)) + { + err("could not open file %s for reading\n",bibFile.data()); + } + QCString doc; + QFileInfo fi(bibFile); + QCString input(fi.size()+1); + f.readBlock(input.rawData(),fi.size()); + f.close(); + input.at(fi.size())='\0'; + int p=0,s; + while ((s=input.find('\n',p))!=-1) + { + QCString line = input.mid(p,s-p); + p=s+1; + + int i; + if ((i = line.find("crossref")) != -1) /* assumption crosreference is on one line and the only item */ + { + int j=line.find("{",i); + int k=line.find("}",i); + if (j!=-1 && k!=-1) + { + QCString label = line.mid(j+1,k-j-1); + if (!m_entries.find(label)) Doxygen::citeDict->insert(label.data()); + } + } + } + } + } + else if (!fi.exists()) + { + err("bib file %s not found!\n",bibFile.data()); + } + bibdata = citeDataList.next(); + } + + // 1. generate file with markers and citations to OUTPUT_DIRECTORY QCString outputDir = Config_getString(OUTPUT_DIRECTORY); QCString citeListFile = outputDir+"/citelist.doc"; f.setName(citeListFile); @@ -154,12 +206,11 @@ void CiteDict::generatePage() const // so bibtex can find them without path (bibtex doesn't support paths or // filenames with spaces!) // Strictly not required when only latex is generated - QStrList &citeDataList = Config_getList(CITE_BIB_FILES); QCString bibOutputDir = outputDir+"/"+bibTmpDir; QCString bibOutputFiles = ""; QDir thisDir; thisDir.mkdir(bibOutputDir); - const char *bibdata = citeDataList.first(); + bibdata = citeDataList.first(); int i = 0; while (bibdata) { @@ -175,10 +226,6 @@ void CiteDict::generatePage() const bibOutputFiles = bibOutputFiles + " " + bibTmpDir + bibTmpFile + QCString().setNum(i) + ".bib"; } } - else if (!fi.exists()) - { - err("bib file %s not found!\n",bibFile.data()); - } bibdata = citeDataList.next(); } diff --git a/templates/html/doxygen.bst b/templates/html/doxygen.bst index c6ae7a8c558..3bdb4f4d331 100644 --- a/templates/html/doxygen.bst +++ b/templates/html/doxygen.bst @@ -549,7 +549,7 @@ FUNCTION {format.tr.number} FUNCTION {format.article.crossref} { - "In " * + "In " * key empty$ { journal empty$ { "need key or journal for " cite$ * " to crossref " * crossref * @@ -561,7 +561,7 @@ FUNCTION {format.article.crossref} } { key * } if$ - " \citelabel{" * crossref * "}" * + " \citelabel{" * "CITEREF_" * crossref * "}" * } FUNCTION {format.crossref.editor} @@ -590,7 +590,7 @@ FUNCTION {format.book.crossref} " of " * } if$ - "" * + "" * editor empty$ editor field.or.null author field.or.null = or @@ -608,12 +608,12 @@ FUNCTION {format.book.crossref} } { format.crossref.editor * } if$ - " \citelabel{" * crossref * "}" * + " \citelabel{" * "CITEREF_" * crossref * "}" * } FUNCTION {format.incoll.inproc.crossref} { - "In " * + "In " * editor empty$ editor field.or.null author field.or.null = or @@ -631,7 +631,7 @@ FUNCTION {format.incoll.inproc.crossref} } { format.crossref.editor * } if$ - " \citelabel{" * crossref * "}" * + " \citelabel{" * "CITEREF_" * crossref * "}" * } FUNCTION {article} diff --git a/testing/012/citelist.xml b/testing/012/citelist.xml old mode 100644 new mode 100755 index f415968bd7f..cb039fd0e9c --- a/testing/012/citelist.xml +++ b/testing/012/citelist.xml @@ -1,22 +1,43 @@ - - - - citelist - Bibliography - - - - - - - [1] - - - DonaldE. Knuth. Tex and Metafont, New Directions in Typesetting. American Mathematical Society and Digital Press, Stanford, 1979. - - - - - - - + + + + citelist + Bibliography + + + + + + + [1] + + + P.Belotti. Disjunctive cuts for non-convex MINLP. In Lee and Leyffer [4], pages 117144. + + + + [2] + + + T.Berthold, S.Heinz, and S.Vigerske. Extending a CIP framework to solve MIQCPs. In Lee and Leyffer [4], pages 427444. + + + + [3] + + + DonaldE. Knuth. Tex and Metafont, New Directions in Typesetting. American Mathematical Society and Digital Press, Stanford, 1979. + + + + [4] + + + Jon Lee and Sven Leyffer, editors. Mixed Integer Nonlinear Programming, volume 154 of The IMA Volumes in Mathematics and its Applications. Springer, 2012. + + + + + + + diff --git a/testing/012/indexpage.xml b/testing/012/indexpage.xml old mode 100644 new mode 100755 index 73fb669a563..e682540385b --- a/testing/012/indexpage.xml +++ b/testing/012/indexpage.xml @@ -1,12 +1,13 @@ - - - - index - My Project - - - - See [1] for more info. - - - + + + + index + My Project + + + + See [3] for more info. + Oter references with crosreference see [1] and [2] for more info. + + + diff --git a/testing/012_cite.dox b/testing/012_cite.dox index 94be5e73237..4b5e40dd18e 100644 --- a/testing/012_cite.dox +++ b/testing/012_cite.dox @@ -4,4 +4,6 @@ // config: CITE_BIB_FILES = $INPUTDIR/sample.bib /** \mainpage * See \cite knuth79 for more info. + * + * Oter references with crosreference see \cite Be09 and \cite BertholdHeinzVigerske2009 for more info. */ diff --git a/testing/sample.bib b/testing/sample.bib index 436e8cd1fc3..c20175d966e 100644 --- a/testing/sample.bib +++ b/testing/sample.bib @@ -5,3 +5,28 @@ @book{knuth79 publisher = "American Mathematical Society and Digital Press", address = "Stanford" } +@InCollection{ BertholdHeinzVigerske2009, + author = {T. Berthold and S. Heinz and S. Vigerske}, + title = {Extending a {CIP} framework to solve {MIQCP}s}, + crossref = {LeLe12}, + pages = {427--444}, + url = {http://doi.org/10.1007/978-1-4614-1927-3_15} +} +@Book{ LeLe12, + title = {Mixed Integer Nonlinear Programming}, + booktitle = {Mixed Integer Nonlinear Programming}, + publisher = {Springer}, + year = {2012}, + editor = {Jon Lee and Sven Leyffer}, + volume = {154}, + series = {The IMA Volumes in Mathematics and its Applications}, + url = {http://doi.org/10.1007/978-1-4614-1927-3}, + issn = {978-1-4614-1926-6} +} +@InCollection{ Be09, + author = {P. Belotti}, + title = {Disjunctive cuts for non-convex {MINLP}}, + crossref = {LeLe12}, + pages = {117--144}, + url = {http://doi.org/10.1007/978-1-4614-1927-3_5} +}