Skip to content

Commit

Permalink
issue #6733 invalid cite anchor id when using crossref
Browse files Browse the repository at this point in the history
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
  • Loading branch information
albert-github committed Jan 4, 2019
1 parent 5d66d2e commit f3e0d5b
Show file tree
Hide file tree
Showing 6 changed files with 143 additions and 47 deletions.
61 changes: 54 additions & 7 deletions src/cite.cpp
Expand Up @@ -22,11 +22,13 @@
#include "language.h"
#include "ftextstream.h"
#include "resourcemgr.h"
#include "doxygen.h"
#include <qdir.h>

//--------------------------------------------------------------------------

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/");
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
{
Expand All @@ -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();
}

Expand Down
12 changes: 6 additions & 6 deletions templates/html/doxygen.bst
Expand Up @@ -549,7 +549,7 @@ FUNCTION {format.tr.number}

FUNCTION {format.article.crossref}
{
"In <a href=" quote$ * "#" * crossref * quote$ * ">" *
"In <a href=" quote$ * "#" * "CITEREF_" * crossref * quote$ * ">" *
key empty$
{ journal empty$
{ "need key or journal for " cite$ * " to crossref " * crossref *
Expand All @@ -561,7 +561,7 @@ FUNCTION {format.article.crossref}
}
{ key * }
if$
"</a> \citelabel{" * crossref * "}" *
"</a> \citelabel{" * "CITEREF_" * crossref * "}" *
}

FUNCTION {format.crossref.editor}
Expand Down Expand Up @@ -590,7 +590,7 @@ FUNCTION {format.book.crossref}
" of " *
}
if$
"<a href=" * quote$ * "#" * crossref * quote$ * ">" *
"<a href=" * "CITEREF_" * quote$ * "#" * crossref * quote$ * ">" *
editor empty$
editor field.or.null author field.or.null =
or
Expand All @@ -608,12 +608,12 @@ FUNCTION {format.book.crossref}
}
{ format.crossref.editor * }
if$
"</a> \citelabel{" * crossref * "}" *
"</a> \citelabel{" * "CITEREF_" * crossref * "}" *
}

FUNCTION {format.incoll.inproc.crossref}
{
"In <a href=" quote$ * "#" * crossref * quote$ * ">" *
"In <a href=" quote$ * "#" * "CITEREF_" * crossref * quote$ * ">" *
editor empty$
editor field.or.null author field.or.null =
or
Expand All @@ -631,7 +631,7 @@ FUNCTION {format.incoll.inproc.crossref}
}
{ format.crossref.editor * }
if$
"</a> \citelabel{" * crossref * "}" *
"</a> \citelabel{" * "CITEREF_" * crossref * "}" *
}

FUNCTION {article}
Expand Down
65 changes: 43 additions & 22 deletions testing/012/citelist.xml 100644 → 100755
@@ -1,22 +1,43 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<doxygen xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="compound.xsd" version="">
<compounddef id="citelist" kind="page">
<compoundname>citelist</compoundname>
<title>Bibliography</title>
<briefdescription>
</briefdescription>
<detaileddescription>
<para>
<variablelist>
<varlistentry>
<term><anchor id="citelist_1CITEREF_knuth79"/>[1]</term>
</varlistentry>
<listitem>
<para>Donald<nonbreakablespace/>E. Knuth. <emphasis>Tex and Metafont, New Directions in Typesetting</emphasis>. American Mathematical Society and Digital Press, Stanford, 1979.</para>
<para/>
</listitem>
</variablelist>
</para>
</detaileddescription>
</compounddef>
</doxygen>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<doxygen xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="compound.xsd" version="">
<compounddef id="citelist" kind="page">
<compoundname>citelist</compoundname>
<title>Bibliography</title>
<briefdescription>
</briefdescription>
<detaileddescription>
<para>
<variablelist>
<varlistentry>
<term><anchor id="citelist_1CITEREF_Be09"/>[1]</term>
</varlistentry>
<listitem>
<para>P.<nonbreakablespace/>Belotti. <ulink url="http://doi.org/10.1007/978-1-4614-1927-3_5">Disjunctive cuts for non-convex MINLP</ulink>. In <ulink url="#CITEREF_LeLe12">Lee and Leyffer</ulink> <ulink url="#CITEREF_LeLe12">[4]</ulink>, pages 117<ndash/>144.</para>
<para/>
</listitem>
<varlistentry>
<term><anchor id="citelist_1CITEREF_BertholdHeinzVigerske2009"/>[2]</term>
</varlistentry>
<listitem>
<para>T.<nonbreakablespace/>Berthold, S.<nonbreakablespace/>Heinz, and S.<nonbreakablespace/>Vigerske. <ulink url="http://doi.org/10.1007/978-1-4614-1927-3_15">Extending a CIP framework to solve MIQCPs</ulink>. In <ulink url="#CITEREF_LeLe12">Lee and Leyffer</ulink> <ulink url="#CITEREF_LeLe12">[4]</ulink>, pages 427<ndash/>444.</para>
<para/>
</listitem>
<varlistentry>
<term><anchor id="citelist_1CITEREF_knuth79"/>[3]</term>
</varlistentry>
<listitem>
<para>Donald<nonbreakablespace/>E. Knuth. <emphasis>Tex and Metafont, New Directions in Typesetting</emphasis>. American Mathematical Society and Digital Press, Stanford, 1979.</para>
<para/>
</listitem>
<varlistentry>
<term><anchor id="citelist_1CITEREF_LeLe12"/>[4]</term>
</varlistentry>
<listitem>
<para>Jon Lee and Sven Leyffer, editors. <ulink url="http://doi.org/10.1007/978-1-4614-1927-3"><emphasis>Mixed Integer Nonlinear Programming</emphasis></ulink>, volume 154 of <emphasis>The IMA Volumes in Mathematics and its Applications</emphasis>. Springer, 2012.</para>
<para/>
</listitem>
</variablelist>
</para>
</detaileddescription>
</compounddef>
</doxygen>
25 changes: 13 additions & 12 deletions testing/012/indexpage.xml 100644 → 100755
@@ -1,12 +1,13 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<doxygen xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="compound.xsd" version="">
<compounddef id="indexpage" kind="page">
<compoundname>index</compoundname>
<title>My Project</title>
<briefdescription>
</briefdescription>
<detaileddescription>
<para>See <ref refid="citelist_1CITEREF_knuth79" kindref="member">[1]</ref> for more info. </para>
</detaileddescription>
</compounddef>
</doxygen>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<doxygen xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="compound.xsd" version="">
<compounddef id="indexpage" kind="page">
<compoundname>index</compoundname>
<title>My Project</title>
<briefdescription>
</briefdescription>
<detaileddescription>
<para>See <ref refid="citelist_1CITEREF_knuth79" kindref="member">[3]</ref> for more info.</para>
<para>Oter references with crosreference see <ref refid="citelist_1CITEREF_Be09" kindref="member">[1]</ref> and <ref refid="citelist_1CITEREF_BertholdHeinzVigerske2009" kindref="member">[2]</ref> for more info. </para>
</detaileddescription>
</compounddef>
</doxygen>
2 changes: 2 additions & 0 deletions testing/012_cite.dox
Expand Up @@ -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.
*/
25 changes: 25 additions & 0 deletions testing/sample.bib
Expand Up @@ -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}
}

0 comments on commit f3e0d5b

Please sign in to comment.