fix nimindexterm in rst2tex/doc2tex [backport] (#19106)

* fix nimindexterm (rst2tex/doc2tex) [backport]

* Add support for indexing in rst
This commit is contained in:
Andrey Makarov
2021-11-09 21:01:47 +03:00
committed by GitHub
parent 46fb855425
commit 997ccc5889
3 changed files with 18 additions and 2 deletions

View File

@@ -63,6 +63,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}
@@ -105,7 +110,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)
@@ -249,5 +256,8 @@ doc.file = """
\maketitle
$content
\printindex
\end{document}
"""

View File

@@ -408,7 +408,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

View File

@@ -301,6 +301,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) =