Skip to content

Commit 1334318

Browse files
a-mrnarimiran
authored andcommitted
fix nimindexterm in rst2tex/doc2tex [backport] (#19106)
* fix nimindexterm (rst2tex/doc2tex) [backport] * Add support for indexing in rst (cherry picked from commit 997ccc5)
1 parent 95dce90 commit 1334318

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

config/nimdoc.tex.cfg

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ doc.file = """
5555
%
5656
% Compile it by: xelatex (up to 3 times to get labels generated)
5757
% -------
58+
% For example:
59+
% xelatex file.tex
60+
% xelatex file.tex
61+
% makeindex file
62+
% xelatex file.tex
5863
%
5964
\documentclass[a4paper,11pt]{article}
6065
\usepackage[a4paper,xetex,left=3cm,right=3cm,top=1.5cm,bottom=2cm]{geometry}
@@ -97,7 +102,9 @@ doc.file = """
97102
\usepackage{parskip} % paragraphs delimited by vertical space, no indent
98103
\usepackage{graphicx}
99104
100-
\newcommand{\nimindexterm}[2]{#2\label{#1}}
105+
\usepackage{makeidx}
106+
\newcommand{\nimindexterm}[2]{#2\index{#2}\label{#1}}
107+
\makeindex
101108
102109
\usepackage{dingbat} % for \carriagereturn, etc
103110
\usepackage{fvextra} % for code blocks (works better than original fancyvrb)
@@ -241,5 +248,8 @@ doc.file = """
241248
\maketitle
242249

243250
$content
251+
252+
\printindex
253+
244254
\end{document}
245255
"""

lib/packages/docutils/rstgen.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ proc renderIndexTerm*(d: PDoc, n: PRstNode, result: var string) =
406406
var term = ""
407407
renderAux(d, n, term)
408408
setIndexTerm(d, changeFileExt(extractFilename(d.filename), HtmlExt), id, term, d.currentSection)
409-
dispA(d.target, result, "<span id=\"$1\">$2</span>", "\\nimindexterm{$2}{$1}",
409+
dispA(d.target, result, "<span id=\"$1\">$2</span>", "\\nimindexterm{$1}{$2}",
410410
[id, term])
411411

412412
type

tools/kochdocs.nim

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,12 @@ proc nim2pdf(src: string, dst: string, nimArgs: string) =
298298
# `>` should work on windows, if not, we can use `execCmdEx`
299299
let cmd = "xelatex -interaction=nonstopmode -output-directory=$# $# > $#" % [outDir.quoteShell, texFile.quoteShell, xelatexLog.quoteShell]
300300
exec(cmd) # on error, user can inspect `xelatexLog`
301+
if i == 1: # build .ind file
302+
var texFileBase = texFile
303+
texFileBase.removeSuffix(".tex")
304+
let cmd = "makeindex $# > $#" % [
305+
texFileBase.quoteShell, xelatexLog.quoteShell]
306+
exec(cmd)
301307
moveFile(texFile.changeFileExt("pdf"), dst)
302308

303309
proc buildPdfDoc*(nimArgs, destPath: string) =

0 commit comments

Comments
 (0)