Skip to content

Commit 369b770

Browse files
committed
Support [@pxxxx]{.title} as a way to inject a title of the paper into the citation.
1 parent ed8b738 commit 369b770

File tree

8 files changed

+80
-17
lines changed

8 files changed

+80
-17
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,10 @@ In-text citations look like this: `[@id]`
424424

425425
![](img/citation.png)
426426

427+
You may also include the title of the paper like `[@P1240R2]{.title}` which generates:
428+
429+
![](img/citetitle.png)
430+
427431
### References
428432

429433
#### Automatic References

TEST.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -396,9 +396,12 @@ There are three supported styles of note:
396396
Automatic references are written as `[@N4762]` and renders as [@N4762].
397397
Anything in <https://wg21.link/index.yaml> are linked automatically.
398398
399-
- `N` Papers (e.g., `[@N3887]` [@N3887])
400-
- `P` Papers (e.g., `[@P1371R1]` [@P1371R1])
401-
- CWG Issues (e.g., `[@CWG1234]` [@CWG1234])
402-
- LWG Issues (e.g., `[@LWG1234]` [@LWG1234])
403-
- Github Edits (e.g, `[@EDIT1234]` [@EDIT1234])
404-
- Standing Documents (e.g., `[@SD6]` [@SD6])
399+
- `N` Papers (e.g., `[@N3887]` → [@N3887])
400+
- `P` Papers (e.g., `[@P1371R1]` → [@P1371R1])
401+
- CWG Issues (e.g., `[@CWG1234]` → [@CWG1234])
402+
- LWG Issues (e.g., `[@LWG1234]` → [@LWG1234])
403+
- Github Edits (e.g, `[@EDIT1234]` → [@EDIT1234])
404+
- Standing Documents (e.g., `[@SD6]` → [@SD6])
405+
406+
You may also write `[@P2996R8]{.title}`{.default} to include the title of the paper,
407+
and renders as: [@P2996R8]{.title}.

data/csl/wg21.csl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,14 @@
101101
<sort>
102102
<key variable="citation-label"/>
103103
</sort>
104-
<layout prefix="[" suffix="]" delimiter=",">
105-
<group delimiter=":">
106-
<text variable="citation-label"/>
107-
<text variable="locator"/>
104+
<layout delimiter=",">
105+
<group delimiter=" ">
106+
<text variable="citation-label" prefix="[" suffix="]"/>
107+
<choose>
108+
<if variable="locator">
109+
<text macro="title" prefix="(" suffix=")"/>
110+
</if>
111+
</choose>
108112
</group>
109113
</layout>
110114
</citation>

data/defaults.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ self-contained: true
1717
data-dir: ${DATADIR}
1818
1919
filters:
20+
- citetitle.py
2021
- citeproc
2122
- wg21.py
2223

data/filters/citetitle.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/env python3
2+
3+
# MPark.WG21
4+
#
5+
# Copyright Michael Park, 2025
6+
#
7+
# Distributed under the Boost Software License, Version 1.0.
8+
# (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
9+
10+
import panflute as pf
11+
12+
"""
13+
This filter is separate from `wg21.py` because it needs to run before `citeproc`.
14+
`wg21.py` currently needs to run after `citeproc` due to `citation_link` (may be others too).
15+
16+
The mechanism is a bit convoluted, but basically... `wg21.csl` is the CSL definition
17+
that determines how references are handled and rendered. The logic there is to optionally
18+
display the title of the reference if a "locator" is present. I don't currently know of
19+
another way to inject a cite-specific thing into the citation.
20+
21+
So, for example `[@Pxxxx]` is a citation without a locator, whereas `[@Pxxxx{}]` is
22+
a citation with a locator. Note the "{}" suffix. This is sufficient to inject the title.
23+
However, since this syntax is rather unfamiliar and cryptic, we offer `[@Pxxxx]{.title}`
24+
instead. This filter transforms `[@Pxxxx]{.title}` into `[@Pxxxx{}]`.
25+
"""
26+
27+
def citetitle(elem, doc):
28+
if not (
29+
isinstance(elem, pf.Span) and
30+
elem.classes == ['title'] and
31+
len(elem.content) == 1 and
32+
isinstance(elem.content[0], pf.Cite)
33+
):
34+
return None
35+
36+
for citation in elem.content[0].citations:
37+
citation.suffix.append(pf.Str('{}'))
38+
39+
return elem
40+
41+
if __name__ == '__main__':
42+
pf.run_filter(citetitle)

generated/TEST.html

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -932,23 +932,27 @@ <h1 data-number="7" id="notes"><span class="header-section-number">7</span> Note
932932
</ul>
933933
<h1 data-number="8" id="citation"><span class="header-section-number">8</span> Citation<a href="#citation" class="self-link"></a></h1>
934934
<p>Automatic references are written as <code class="sourceCode cpp"><span class="op">[@</span>N4762<span class="op">]</span></code>
935-
and renders as <span class="citation" data-cites="N4762">[<a href="https://wg21.link/n4762" role="doc-biblioref">N4762</a>]</span>.
935+
and renders as <span class="citation" data-cites="N4762"><a href="https://wg21.link/n4762" role="doc-biblioref">[N4762]</a></span>.
936936
Anything in <a href="https://wg21.link/index.yaml" class="uri">https://wg21.link/index.yaml</a> are linked
937937
automatically.</p>
938938
<ul>
939939
<li><code class="sourceCode cpp">N</code> Papers (e.g., <code class="sourceCode cpp"><span class="op">[@</span>N3887<span class="op">]</span></code>
940-
<span class="citation" data-cites="N3887">[<a href="https://wg21.link/n3887" role="doc-biblioref">N3887</a>]</span>)</li>
940+
<span class="citation" data-cites="N3887"><a href="https://wg21.link/n3887" role="doc-biblioref">[N3887]</a></span>)</li>
941941
<li><code class="sourceCode cpp">P</code> Papers (e.g., <code class="sourceCode cpp"><span class="op">[@</span>P1371R1<span class="op">]</span></code>
942-
<span class="citation" data-cites="P1371R1">[<a href="https://wg21.link/p1371r1" role="doc-biblioref">P1371R1</a>]</span>)</li>
942+
<span class="citation" data-cites="P1371R1"><a href="https://wg21.link/p1371r1" role="doc-biblioref">[P1371R1]</a></span>)</li>
943943
<li>CWG Issues (e.g., <code class="sourceCode cpp"><span class="op">[@</span>CWG1234<span class="op">]</span></code>
944-
<span class="citation" data-cites="CWG1234">[<a href="https://wg21.link/cwg1234" role="doc-biblioref">CWG1234</a>]</span>)</li>
944+
<span class="citation" data-cites="CWG1234"><a href="https://wg21.link/cwg1234" role="doc-biblioref">[CWG1234]</a></span>)</li>
945945
<li>LWG Issues (e.g., <code class="sourceCode cpp"><span class="op">[@</span>LWG1234<span class="op">]</span></code>
946-
<span class="citation" data-cites="LWG1234">[<a href="https://wg21.link/lwg1234" role="doc-biblioref">LWG1234</a>]</span>)</li>
946+
<span class="citation" data-cites="LWG1234"><a href="https://wg21.link/lwg1234" role="doc-biblioref">[LWG1234]</a></span>)</li>
947947
<li>Github Edits (e.g, <code class="sourceCode cpp"><span class="op">[@</span>EDIT1234<span class="op">]</span></code>
948-
<span class="citation" data-cites="EDIT1234">[<a href="https://wg21.link/edit1234" role="doc-biblioref">EDIT1234</a>]</span>)</li>
948+
<span class="citation" data-cites="EDIT1234"><a href="https://wg21.link/edit1234" role="doc-biblioref">[EDIT1234]</a></span>)</li>
949949
<li>Standing Documents (e.g., <code class="sourceCode cpp"><span class="op">[@</span>SD6<span class="op">]</span></code>
950-
<span class="citation" data-cites="SD6">[<a href="https://wg21.link/sd6" role="doc-biblioref">SD6</a>]</span>)</li>
950+
<span class="citation" data-cites="SD6"><a href="https://wg21.link/sd6" role="doc-biblioref">[SD6]</a></span>)</li>
951951
</ul>
952+
<p>You may also write
953+
<code class="sourceCode default">[@P2996R8]{.title}</code> to include
954+
the title of the paper, and renders as: <span class="title"><span class="citation" data-cites="P2996R8"><a href="https://wg21.link/p2996r8" role="doc-biblioref">[P2996R8]
955+
(Reflection for C++26)</a></span></span>.</p>
952956
<h1 data-number="9" id="bibliography"><span class="header-section-number">9</span> References<a href="#bibliography" class="self-link"></a></h1>
953957
<div id="refs" class="references csl-bib-body hanging-indent" data-entry-spacing="1" role="doc-bibliography">
954958
<div id="ref-CWG1234" class="csl-entry" role="doc-biblioentry">
@@ -973,6 +977,11 @@ <h1 data-number="9" id="bibliography"><span class="header-section-number">9</spa
973977
[P1371R1] Sergei Murzin, Michael Park, David Sankel, Dan Sarginson.
974978
2019-06-17. Pattern Matching. <a href="https://wg21.link/p1371r1"><div class="csl-block">https://wg21.link/p1371r1</div></a>
975979
</div>
980+
<div id="ref-P2996R8" class="csl-entry" role="doc-biblioentry">
981+
[P2996R8] Barry Revzin, Wyatt Childers, Peter Dimov, Andrew Sutton,
982+
Faisal Vali, Daveed Vandevoorde, Dan Katz. 2024-12-17. Reflection for
983+
C++26. <a href="https://wg21.link/p2996r8"><div class="csl-block">https://wg21.link/p2996r8</div></a>
984+
</div>
976985
<div id="ref-SD6" class="csl-entry" role="doc-biblioentry">
977986
[SD6] SG10 Feature Test Recommendations. <a href="https://wg21.link/sd6"><div class="csl-block">https://wg21.link/sd6</div></a>
978987
</div>

generated/TEST.pdf

73.2 KB
Binary file not shown.

img/citetitle.png

17.1 KB
Loading

0 commit comments

Comments
 (0)