Skip to content

Commit

Permalink
fix nimindexterm in rst2tex/doc2tex [backport] (#19106)
Browse files Browse the repository at this point in the history
* fix nimindexterm (rst2tex/doc2tex) [backport]

* Add support for indexing in rst

(cherry picked from commit 997ccc5)
  • Loading branch information
a-mr authored and narimiran committed Nov 11, 2021
1 parent 95dce90 commit 1334318
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
12 changes: 11 additions & 1 deletion config/nimdoc.tex.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ doc.file = """
%
% Compile it by: xelatex (up to 3 times to get labels generated)
% -------
% For example:
% xelatex file.tex
% xelatex file.tex
% makeindex file
% xelatex file.tex
%
\documentclass[a4paper,11pt]{article}
\usepackage[a4paper,xetex,left=3cm,right=3cm,top=1.5cm,bottom=2cm]{geometry}
Expand Down Expand Up @@ -97,7 +102,9 @@ doc.file = """
\usepackage{parskip} % paragraphs delimited by vertical space, no indent
\usepackage{graphicx}
\newcommand{\nimindexterm}[2]{#2\label{#1}}
\usepackage{makeidx}
\newcommand{\nimindexterm}[2]{#2\index{#2}\label{#1}}
\makeindex
\usepackage{dingbat} % for \carriagereturn, etc
\usepackage{fvextra} % for code blocks (works better than original fancyvrb)
Expand Down Expand Up @@ -241,5 +248,8 @@ doc.file = """
\maketitle

$content

\printindex

\end{document}
"""
2 changes: 1 addition & 1 deletion lib/packages/docutils/rstgen.nim
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ proc renderIndexTerm*(d: PDoc, n: PRstNode, result: var string) =
var term = ""
renderAux(d, n, term)
setIndexTerm(d, changeFileExt(extractFilename(d.filename), HtmlExt), id, term, d.currentSection)
dispA(d.target, result, "<span id=\"$1\">$2</span>", "\\nimindexterm{$2}{$1}",
dispA(d.target, result, "<span id=\"$1\">$2</span>", "\\nimindexterm{$1}{$2}",
[id, term])

type
Expand Down
6 changes: 6 additions & 0 deletions tools/kochdocs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,12 @@ proc nim2pdf(src: string, dst: string, nimArgs: string) =
# `>` should work on windows, if not, we can use `execCmdEx`
let cmd = "xelatex -interaction=nonstopmode -output-directory=$# $# > $#" % [outDir.quoteShell, texFile.quoteShell, xelatexLog.quoteShell]
exec(cmd) # on error, user can inspect `xelatexLog`
if i == 1: # build .ind file
var texFileBase = texFile
texFileBase.removeSuffix(".tex")
let cmd = "makeindex $# > $#" % [
texFileBase.quoteShell, xelatexLog.quoteShell]
exec(cmd)
moveFile(texFile.changeFileExt("pdf"), dst)

proc buildPdfDoc*(nimArgs, destPath: string) =
Expand Down

0 comments on commit 1334318

Please sign in to comment.