Skip to content

Commit a29377b

Browse files
committed
latexgen: fix doxy*section references
This commit fixes an advanced usage of doxygen, more especially latex doxylink usage. Standard doxylink is a simple hyperlink: ```latex \newcommand{\doxylink}[2]{ \mbox{\hyperlink{#1}{#2}} } ``` This simple reference is OK for digital pdf. But, in case of printed document, it lacks location information. We extended doxylink like this, to add section number and title: ```latex \renewcommand{\doxylink}[2]{ \hyperlink{#1}{#2}, in \ref{#1} \nameref{#1} } ``` The latex compiles well. But the generated latex is wrong. In the pdf, we observe that the hyperlink is good, but the `ref` and `nameref` point to the previous section. Digging into generated .tex files, we found the following construct: ```latex \Hypertarget{header_8h_ad8a2dfa8cbec508ec4cf97b2c5452797}\label{header_8h_ad8a2dfa8cbec508ec4cf97b2c5452797} \index{header.h@{header.h}!bar@{bar}} \index{bar@{bar}!header.h@{header.h}} \doxysubsubsection{\texorpdfstring{bar()}{bar()}} ``` We can see that the `\label` is placed before `\doxysubsubsection`. doxylink points to `label`. And in this case, `\label` is part of the previous `doxy*section`. This commit fixes this behavior, by splitting the function `startDoxyAnchor` into `startDoxyAnchor` and `addLabel`. Then, the `Hypertarget` is placed before the `doxy*section`, and the `label` is placed after. We want the `Hypertarget` to be placed before the `doxy*section`. It allows, when the user click, to land just before the section title, and then see the section title. The resulted generated .tex is the following: ```latex \Hypertarget{header_8h_a49a4b11e50430aa0a78de989ea99e082}\index{header.h@{header.h}!bar@{bar}} \index{bar@{bar}!header.h@{header.h}} \doxysubsubsection{\texorpdfstring{bar()}{bar()}} {\footnotesize\ttfamily \label{header_8h_a49a4b11e50430aa0a78de989ea99e082} ``` This behavior can be tested with a simple header file like this: ```c /** @file header.h */ /** foo function */ void foo(); /** bar function, see @ref foo */ void bar(); ```
1 parent 6d05f80 commit a29377b

File tree

14 files changed

+45
-7
lines changed

14 files changed

+45
-7
lines changed

src/docbookgen.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -936,6 +936,10 @@ void DocbookGenerator::endDoxyAnchor(const QCString &,const QCString &)
936936
{
937937
DB_GEN_C
938938
}
939+
void DocbookGenerator::addLabel(const QCString &,const QCString &)
940+
{
941+
DB_GEN_C
942+
}
939943
void DocbookGenerator::startMemberDocName(bool)
940944
{
941945
DB_GEN_C

src/docbookgen.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ class DocbookGenerator : public OutputGenerator
220220
const QCString &anchor,const QCString &name,
221221
const QCString &args);
222222
void endDoxyAnchor(const QCString &fileName,const QCString &anchor);
223+
void addLabel(const QCString &,const QCString &);
223224
void writeLatexSpacing(){DB_GEN_EMPTY}
224225
void writeStartAnnoItem(const QCString &,const QCString &,
225226
const QCString &,const QCString &){DB_GEN_NEW};

src/htmlgen.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1675,6 +1675,10 @@ void HtmlGenerator::endDoxyAnchor(const QCString &,const QCString &)
16751675
{
16761676
}
16771677

1678+
void HtmlGenerator::addLabel(const QCString &,const QCString &)
1679+
{
1680+
}
1681+
16781682
void HtmlGenerator::startParagraph(const QCString &classDef)
16791683
{
16801684
if (!classDef.isEmpty())

src/htmlgen.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ class HtmlGenerator : public OutputGenerator
203203
const QCString &anchor,const QCString &name,
204204
const QCString &args);
205205
void endDoxyAnchor(const QCString &fName,const QCString &anchor);
206+
void addLabel(const QCString &,const QCString &);
206207
void writeLatexSpacing() {}
207208
void writeStartAnnoItem(const QCString &type,const QCString &file,
208209
const QCString &path,const QCString &name);

src/latexgen.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1565,17 +1565,21 @@ void LatexGenerator::startDoxyAnchor(const QCString &fName,const QCString &,
15651565
if (!anchor.isEmpty()) m_t << "_" << anchor;
15661566
m_t << "}";
15671567
}
1568+
}
1569+
1570+
void LatexGenerator::endDoxyAnchor(const QCString &/* fName */,const QCString &/* anchor */)
1571+
{
1572+
}
1573+
1574+
void LatexGenerator::addLabel(const QCString &fName, const QCString &anchor)
1575+
{
15681576
m_t << "\\label{";
15691577
if (!fName.isEmpty()) m_t << stripPath(fName);
15701578
if (!anchor.isEmpty()) m_t << "_" << anchor;
15711579
if (m_insideTableEnv) m_t << "}";
15721580
m_t << "} \n";
15731581
}
15741582

1575-
void LatexGenerator::endDoxyAnchor(const QCString &/* fName */,const QCString &/* anchor */)
1576-
{
1577-
}
1578-
15791583
void LatexGenerator::writeAnchor(const QCString &fName,const QCString &name)
15801584
{
15811585
//printf("LatexGenerator::writeAnchor(%s,%s)\n",fName,name);

src/latexgen.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ class LatexGenerator : public OutputGenerator
191191
void endMemberDoc(bool);
192192
void startDoxyAnchor(const QCString &,const QCString &,const QCString &,const QCString &,const QCString &);
193193
void endDoxyAnchor(const QCString &,const QCString &);
194+
void addLabel(const QCString &,const QCString &);
194195
void writeChar(char c);
195196
void writeLatexSpacing() { m_t << "\\hspace{0.3cm}"; }
196197
void writeStartAnnoItem(const QCString &type,const QCString &file,

src/mangen.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,10 @@ void ManGenerator::startDoxyAnchor(const QCString &,const QCString &manName,
542542
}
543543
}
544544

545+
void ManGenerator::addLabel(const QCString &,const QCString &)
546+
{
547+
}
548+
545549
void ManGenerator::endMemberDoc(bool)
546550
{
547551
m_t << "\"\n";

src/mangen.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ class ManGenerator : public OutputGenerator
162162
void endMemberDoc(bool);
163163
void startDoxyAnchor(const QCString &,const QCString &,const QCString &,const QCString &,const QCString &);
164164
void endDoxyAnchor(const QCString &,const QCString &) {}
165+
void addLabel(const QCString &,const QCString &);
165166
void writeLatexSpacing() {}
166167
void writeStartAnnoItem(const QCString &type,const QCString &file,
167168
const QCString &path,const QCString &name);

src/memberdef.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2252,6 +2252,7 @@ void MemberDefImpl::writeDeclaration(OutputList &ol,
22522252
doxyName.prepend(cdname+getLanguageSpecificSeparator(getLanguage()));
22532253
}
22542254
ol.startDoxyAnchor(cfname,cname,anchor(),doxyName,doxyArgs);
2255+
ol.addLabel(cfname,anchor());
22552256
}
22562257

22572258
if (!detailsVisible)
@@ -3183,6 +3184,7 @@ void MemberDefImpl::_writeEnumValues(OutputList &ol,const Definition *container,
31833184

31843185
ol.startDescTableTitle();
31853186
ol.startDoxyAnchor(cfname,cname,fmd->anchor(),fmd->name(),fmd->argsString());
3187+
ol.addLabel(cfname,anchor());
31863188
first=FALSE;
31873189
ol.docify(fmd->name());
31883190
ol.disableAllBut(OutputType::Man);
@@ -3487,8 +3489,9 @@ void MemberDefImpl::writeDocumentation(const MemberList *ml,
34873489
{
34883490
if (vmd->isEnumerate() && match.str()==vmd->name())
34893491
{
3490-
ol.startDoxyAnchor(cfname,cname,memAnchor,doxyName,doxyArgs);
3492+
ol.startDoxyAnchor(cfname, cname, memAnchor, doxyName, doxyArgs);
34913493
ol.startMemberDoc(ciname,name(),memAnchor,name(),memCount,memTotal,showInline);
3494+
ol.addLabel(cfname, memAnchor);
34923495
std::string prefix = match.prefix().str();
34933496
std::string suffix = match.suffix().str();
34943497
linkifyText(TextGeneratorOLImpl(ol),scopedContainer,getBodyDef(),this,prefix.c_str());
@@ -3504,8 +3507,9 @@ void MemberDefImpl::writeDocumentation(const MemberList *ml,
35043507
ClassDef *annoClassDef=getClassDefOfAnonymousType();
35053508
QCString typeName;
35063509
if (annoClassDef) typeName=annoClassDef->compoundTypeString();
3507-
ol.startDoxyAnchor(cfname,cname,memAnchor,doxyName,doxyArgs);
3510+
ol.startDoxyAnchor(cfname, cname, memAnchor, doxyName, doxyArgs);
35083511
ol.startMemberDoc(ciname,name(),memAnchor,"["+typeName+"]",memCount,memTotal,showInline);
3512+
ol.addLabel(cfname, memAnchor);
35093513
// search for the last anonymous compound name in the definition
35103514

35113515
ol.startMemberDocName(isObjCMethod());
@@ -3525,8 +3529,9 @@ void MemberDefImpl::writeDocumentation(const MemberList *ml,
35253529
}
35263530
else // not an enum value or anonymous compound
35273531
{
3528-
ol.startDoxyAnchor(cfname,cname,memAnchor,doxyName,doxyArgs);
3532+
ol.startDoxyAnchor(cfname, cname, memAnchor, doxyName, doxyArgs);
35293533
ol.startMemberDoc(ciname,name(),memAnchor,title,memCount,memTotal,showInline);
3534+
ol.addLabel(cfname, memAnchor);
35303535

35313536
if (!m_metaData.isEmpty() && getLanguage()==SrcLangExt::Slice)
35323537
{
@@ -3885,6 +3890,7 @@ void MemberDefImpl::writeMemberDocSimple(OutputList &ol, const Definition *conta
38853890
{
38863891
ol.startInlineMemberType();
38873892
ol.startDoxyAnchor(cfname,cname,memAnchor,doxyName,doxyArgs);
3893+
ol.addLabel(cfname,anchor());
38883894

38893895
QCString ts = fieldType();
38903896

src/memberlist.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ void MemberList::writePlainDeclarations(OutputList &ol, bool inGroup,
394394
if (!detailsLinkable)
395395
{
396396
ol.startDoxyAnchor(md->getOutputFileBase(),QCString(),md->anchor(),md->name(),QCString());
397+
ol.addLabel(md->getOutputFileBase(),md->anchor());
397398
}
398399
if (md->isSliceLocal())
399400
{

0 commit comments

Comments
 (0)