summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/forest/forest-index.sty
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/latex/forest/forest-index.sty')
-rw-r--r--Master/texmf-dist/tex/latex/forest/forest-index.sty158
1 files changed, 123 insertions, 35 deletions
diff --git a/Master/texmf-dist/tex/latex/forest/forest-index.sty b/Master/texmf-dist/tex/latex/forest/forest-index.sty
index e470d5ffe9e..6bd6fb774ed 100644
--- a/Master/texmf-dist/tex/latex/forest/forest-index.sty
+++ b/Master/texmf-dist/tex/latex/forest/forest-index.sty
@@ -8,7 +8,7 @@
%%
%% `forest-index' is an indexing system for the documentation of package `forest', using the package itself.
%%
-%% Copyright (c) 2015 Saso Zivanovic
+%% Copyright (c) 2016 Saso Zivanovic
%% (Sa\v{s}o \v{Z}ivanovi\'{c})
%% saso.zivanovic@guest.arnes.si
%%
@@ -42,10 +42,8 @@
{\let\forestindex@resolvekey\forestindex@resolvekey@shortorlong}%
\forestindex@index{example}{#1}{#3}}
\DeclareDocumentCommand\indexitem{D(){} O{} t> m}{%
- \IfBooleanTF{#3}
- {\let\forestindex@resolvekey\forestindex@resolvekey@long}
- {\let\forestindex@resolvekey\forestindex@resolvekey@shortorlong}%
- \forestindex@index{definition}{default={#1},print format=item,#2}{#4}}
+ \let\forestindex@resolvekey\forestindex@resolvekey@long
+ \forestindex@index{definition}{default={#1},#2,print format+=item}{#4}}
\DeclareDocumentCommand\indexset{O{} t> m}{%
\IfBooleanTF{#2}
{\let\forestindex@resolvekey\forestindex@resolvekey@long}
@@ -58,15 +56,24 @@
\forestindex@index{#1}{#2}{#4}%
}
\def\forestindex@index#1#2#3{%
- \forcsvlist{\forestindex@forkey{#1}{#2}}{#3}%
+ {\forcsvlist{\forestindex@forkey{#1}{#2}}{#3}}%
}
\def\forestindex@forkey#1#2#3{%
\forestindex@resolvekey{#3}%
- \forestset{@index/.process args={__o}{#1}{#2}{\forestindex@fullkey}}%
+ %\forestset{@index/.process={__o}{#1}{#2}{\forestindex@fullkey}}
+ \edef\forest@marshal{%
+ \noexpand\forestindex@index@{%
+ {\unexpanded{#1}}%
+ {\unexpanded{#2}}%
+ {\expandonce{\forestindex@fullkey}}%
+ }%
+ }\forest@marshal
}
+\def\forestindex@index@#1{\forestset{@index/.process={__o}#1}}
\forestset{
declare boolean register=print,
declare boolean register=index,
+ declare boolean register=short, short,
declare toks={key}{},
declare toks={argument}{},
declare toks={index key}{},
@@ -99,10 +106,11 @@
if n=0{
content/.option=key,
}{
- content/.wrap 2 pgfmath args={##1>##2}{content("!parent")}{key},
+ content/.process={OOw2} {!parent.content} {key} {##1>##2},
}
}{},
for root'={
+ if strequal/.process={O}{!root.name}{@unknown}{TeX=\global\forest@memoizing@ok@false}{},
for tree={
print form/.option=key,
index key/.option=key,
@@ -113,7 +121,7 @@
every index begin,
#1,
},
- for reverse={ancestors}{on invalid={fake}{@@index/\forestoption{name}/.try}},
+ for reverse={current and ancestors}{on invalid={fake}{@@index/\forestoption{name}/.try}},
if index entry type={definition}{}{%
on invalid={fake}{@@index/\forestoption{name}/.try},
},
@@ -125,11 +133,11 @@
if index entry type={definition}{save@foridx}{},
},
stage={},
- if={index()||print()}{
+ if index={
index@hypertarget/.expanded={.\forestoption{index key}},
for descendants={
- index@hypertarget/.wrap 2 pgfmath args={##1.##2}%
- {index@hypertarget("!parent")}{index_key},
+ index@hypertarget/.process= {OOw2}
+ {!parent.index@hypertarget} {index key} {##1.##2},
},
}{},
if index={
@@ -164,11 +172,11 @@
},
},
temptoksa={},
- result={},
+ result'={},
if n children=0{tempboola}{not tempboola},
where index form={}{}{
- if tempboola={temptoksd/.expanded={\noexpand\protect\noexpand\hypertarget{%
- \forestoption{index@hypertarget}}{}}}{temptoksd={}},
+ temptoksd/.expanded={\noexpand\protect\noexpand\hypertarget{%
+ \forestoption{index@hypertarget}}{}},
result+/.expanded={%
\forestregister{temptoksa}%
\forestoption{index key}%
@@ -180,7 +188,7 @@
temptoksb={},
},
result+/.expanded={|indexpagenumber\forestregister{index entry type}},
- TeX/.expanded={\noexpand\forestindex@LaTeX@index{\forestregister{result}}},
+ TeX and memoize/.expanded={\noexpand\forestindex@LaTeX@index{\forestregister{result}}},
},
endgroup
}{},
@@ -192,7 +200,7 @@
process keylist'={print format}{current},
print form/.register=result,
},
- for first leaf'={TeX={\forestoption{print form}}},
+ for first leaf'={TeX and memoize/.expanded={\forestoption{print form}}},
endgroup,
}{},
}
@@ -216,8 +224,8 @@
name'/.option=key,
content={#1},
}{
- name'/.wrap 2 pgfmath args={##1>##2}{name("!parent")}{key},
- content/.wrap pgfmath arg={##1>#1}{content("!parent")},
+ name'/.process={OOw2} {!parent.name} {key} {##1>##2},
+ content/.process={Ow1} {!parent.content} {##1>#1},
},
}
},
@@ -227,29 +235,33 @@
Autoforward register={set}{##1},
save@session/.style={@@index/\forestoption{name}/.global style/.register=set},
save@foridx/.style={
- if={strequal(name("!root"),"@unknown")}{}{
+ if strequal/.process={O}{!root.name}{@unknown}{}{
if set={}{}{
- TeX={%
- \immediate\write\forestindex@out{%
- \string\indexloadsettings{\forestoption{name}}{\forestregister{set}}%
+ TeX and memoize/.expanded={%
+ \noexpand\immediate\noexpand\write\noexpand\forestindex@out{%
+ \noexpand\string\noexpand\indexloadsettings\noexpand\unexpanded{{\forestoption{name}}{\forestregister{set}}}%
}%
},
},
- if={strequal(key(),content())}{}{
- TeX={%
- \immediate\write\forestindex@out{%
- \string\indexdefineshortkey{\forestoption{key}}{\forestoption{content}}%
+ },
+ if key/.process={O}{content} {} {%
+ if short={
+ TeX and memoize/.expanded={%
+ \noexpand\immediate\noexpand\write\noexpand\forestindex@out{%
+ \noexpand\string\noexpand\indexdefineshortkey\noexpand\unexpanded{{\forestoption{key}}{\forestoption{content}}}%
}%
- }
+ }{}%
}
}
- },
+ }
}
\def\indexloadsettings#1#2{%
\pgfkeysifdefined{/forest/@@index/#1/.@cmd}{%
\forestindex@loadsettings@warning{#1}%
}{}%
- \forestset{@@index/#1/.global style={#2}}%
+ % #s in #2 are doubled; the following \def removes one layer of doubling
+ \def\forest@temp{#2}%
+ \forestset{@@index/#1/.global style/.expand once=\forest@temp}%
}
\def\forestindex@loadsettings@warning#1{%
\PackageWarning{forest-index}{Forest index key "#1" was configured more than once!
@@ -304,8 +316,8 @@
normal color/.initial=blue,
definition color/.initial=red,
example color/.initial=darkgreen,
- print in color/.style={if stage={print}{result=\protect\textcolor{%
- \pgfkeysvalueof{/forest/#1 color}}{##1}}{}},
+ print in color/.style={if stage={print}{result/.expanded=\noexpand\protect\noexpand\textcolor{%
+ \pgfkeysvalueof{/forest/#1 color}}{\unexpanded{##1}}}{}},
print in color/.default=\forestregister{index entry type},
hyper/.style={
if stage={index}{}{
@@ -340,9 +352,10 @@
\forestset{
declare toks register=default,
default={},
- item/.style={result/.wrap 4 pgfmath args={%
- \item[,##2,##3]{##4}%
- }{}{default}{print_form("!parent")}{result},
+ item/.style={
+ result/.process= {_RORw4}
+ {} {default} {!parent.print form} {result}
+ {\item[,##2,##3]{##4}},
},
}
\pgfkeys{/handlers/.global style/.code=\pgfkeys{\pgfkeyscurrentpath/.global code=\pgfkeysalso{#1}}}
@@ -359,9 +372,84 @@
\pgfkeys@temptoks{#2}\expandafter\xdef\csname pgfk@#1\endcsname{\the\pgfkeys@temptoks}%
}
\forestset{
+ % unlike pgfmath function strequal, |if strequal| does not expand the compared args!
+ if strequal/.code n args={4}{\ifstrequal{#1}{#2}{\pgfkeysalso{#3}}{\pgfkeysalso{#4}}},
+}
+\forestset{
begingroup/.code={\begingroup},
endgroup/.code={\endgroup},
}
+\newtoks\forest@memo@key
+\newtoks\forest@memo
+\newif\ifforest@memoizing@now@
+\newif\ifforest@memoizing@ok@
+\newif\ifforest@execandmemoize@
+\def\forest@memoize#1{% #1 = \cs
+ \cslet{forest@memo@orig@\string#1}#1%
+ \def#1##1{%
+ \ifforest@memoizing@now@
+ \forest@globalsaveandrestoreifcs{forest@execandmemoize@}{%
+ \global\forest@execandmemoize@false
+ \csname forest@memo@orig@\string#1\endcsname{##1}%
+ }%
+ \else
+ \expandafter\global\expandafter\forest@memo@key\expandafter{\detokenize{forest@memo@#1{##1}}}%
+ \ifcsname\the\forest@memo@key\endcsname
+ \@escapeifif{\csname\the\forest@memo@key\endcsname}%
+ \else
+ \@escapeifif{%
+ \global\forest@memo{}%
+ \global\forest@memoizing@ok@true
+ \global\forest@memoizing@now@true
+ \global\forest@execandmemoize@true
+ \csname forest@memo@orig@\string#1\endcsname{##1}%
+ \global\forest@execandmemoize@false
+ \global\forest@memoizing@now@false
+ \ifforest@memoizing@ok@
+ \csxdef{\the\forest@memo@key}{\the\forest@memo}%
+ \immediate\write\forest@memo@out{%
+ \noexpand\forest@memo@load{\the\forest@memo@key}{\the\forest@memo}%
+ }%
+ \fi
+ }%
+ \fi
+ \fi
+ }%
+}
+\def\forest@memo@load#1#2{%
+ \def\forest@temp@key{#1}%
+ \def\forest@temp@value{#2}%
+ \csxdef{\detokenize\expandafter{\forest@temp@key}}{\expandonce\forest@temp@value}%
+ \immediate\write\forest@memo@out{%
+ \noexpand\forest@memo@load{\detokenize\expandafter{\forest@temp@key}}{\detokenize\expandafter{\forest@temp@value}}%
+ }%
+}
+\forestset{
+ TeX and memoize/.code={\forest@execandmemoize{#1}},
+}
+\def\forest@execandmemoize#1{%
+ \ifforest@execandmemoize@
+ \let\forest@memo@next\forest@execandmemoize@
+ \else
+ \let\forest@memo@next\@gobble
+ \fi
+ \forest@memo@next{#1}%
+ #1%
+}
+\def\forest@execandmemoize@#1{%
+ \gapptotoks\forest@memo{#1}%
+}
+\def\forest@memo@filename{\jobname.memo}
+\newwrite\forest@memo@out
+\immediate\openout\forest@memo@out=\forest@memo@filename.tmp
+\IfFileExists{\forest@memo@filename}{%
+ \input\forest@memo@filename\relax
+}{}%
+\AtEndDocument{%
+ \immediate\closeout\forest@memo@out
+ \forest@file@copy{\forest@memo@filename.tmp}{\forest@memo@filename}%
+}
+\forest@memoize\forestindex@index@
\index(not print,not index)[%
set={
index key=unknown,