-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstacks.dtx
148 lines (141 loc) · 4.31 KB
/
stacks.dtx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
% \iffalse meta-comment
%
% Copyright (C) 2014 by Pieter Belmans
%
% This file may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either
% version 1.2 of this license or (at your option) any later
% version. The latest version of this license is in:
%
% http://www.latex-project.org/lppl.txt
%
% and version 1.2 or later is part of all distributions of
% LaTeX version 1999/12/01 or later.
%
% \fi
% \iffalse
%<package>\NeedsTeXFormat{LaTeX2e}
%<package>\ProvidesPackage{stacks}
%<package> [2014/06/14 v0.1 Automatically include snippets from the Stacks project]
%<package>\RequirePackage{download}
%<package>\RequirePackage{etoolbox}
%<package>\RequirePackage{kvoptions}
%<package>\RequirePackage{xkeyval}
%<package>\RequirePackage{xparse}
%
%
%<*driver>
\documentclass{ltxdoc}
\usepackage{stacks}
\EnableCrossrefs
\CodelineIndex
\RecordChanges
\begin{document}
\DocInput{stacks.dtx}
\end{document}
%</driver>
% \fi
%
% \CheckSum{0}
%
% \GetFileInfo{stacks.sty}
% \DoNotIndex{}
%
% \title{The \textsf{stacks} package
% \thanks{This document corresponds to \textsf{stacks}~\fileversion, dated~\filedate.}}
% \author{Pieter Belmans \\ \texttt{pieterbelmans@gmail.com}}
%
% \maketitle
%
% \begin{abstract}
% Write a description here.
% \end{abstract}
%
% \DescribeMacro{\stacksinclude}
% This macro fetches a tag from the Stacks project. It can be passed the
% following options:
% \begin{description}
% \item[\texttt{[proof\textit{$\langle=b\rangle$}]}] Boolean value; default:
% \texttt{true}. Fetches the proof of the tag (as well as the statement).
% \item[\texttt{[label$=s$]}] String value; error if no value given. Changes
% the label of the tag to $s$. Should only be used on theorem-like
% environments. \emph{N.B.: Conflicts with option \texttt{prefix}.}
% \item[\texttt{[prefix$\langle=s\rangle$]}] String value; default:
% \texttt{stacks-}. Prefixes all labels in this tag with $s$. Useful when
% including entire sections or subsections. \emph{N.B.: Conflicts with option
% \texttt{label}.}
% \end{description}
% As an example, one could include Nakayama's lemma with the command:
% \begin{verbatim}
% \stacksinclude[proof,prefix]{00DV}
% \end{verbatim}
% The label of the included lemma would then be \texttt{stacks-lemma-NAK}.
%
% \section{Implementation}
% \subsection{Global configuration}
% \begin{macrocode}
\makeatletter
\SetupKeyvalOptions{
family = stacks,
prefix = stacks@,
}
\DeclareStringOption[stacks-project]{citation}
\ProcessKeyvalOptions*
\newcommand\stacks@site{http://stacks.math.columbia.edu}
\AtBeginDocument{%
\newtoggle{stacks@usehyperref}%
\@ifpackageloaded{hyperref}{\toggletrue{stacks@usehyperref}}{}
}
% \end{macrocode}
% \subsection{The \texttt{stackscite} command}
% \begin{macrocode}
\DeclareDocumentCommand\stackscite{m}{%
\iftoggle{stacks@usehyperref}{%
\cite[\href{\stacks@site/tag/#1}{tag #1}]{\stacks@citation}%
}{%
\cite[tag #1]{\stacks@citation}%
}
}
% \end{macrocode}
% \subsection{The \texttt{stacksinclude} command}
% \begin{macrocode}
\DeclareDocumentCommand\stacksinclude{om}{%
\renewcommand\stacks@options@proof{false}
\renewcommand\stacks@options@label{}
\renewcommand\stacks@options@prefix{}
\let\oldlabel\label%
\IfNoValueF{#1}{\setkeys{stacks}{#1}}%
\ifnum\pdfstrcmp{\stacks@options@proof}{true}=0%
\download[#2-proof.tex]{\stacks@site/data/tag/#2/content/full/raw}%
\input{#2-proof}%
\else\ifnum\pdfstrcmp{\stacks@options@proof}{false}=0%
\download[#2.tex]{\stacks@site/data/tag/#2/content/statement/raw}%
\input{#2}%
\else
provided a wrong argument (\texttt{\stacks@options@proof}) to the
\texttt{proof} option
\fi\fi%
\let\label\oldlabel%
}
% \end{macrocode}
% \subsection{Options processing for the \texttt{stacksinclude} command}
% \begin{macrocode}
\newcommand\stacks@options@proof{false}
\define@key{stacks}{proof}[true]{\renewcommand\stacks@options@proof{#1}}
\newcommand\stacks@options@label{}
\define@key{stacks}{label}{%
\renewcommand\stacks@options@label{#1}%
\renewcommand{\label}[1]{%
\oldlabel{\stacks@options@label}%
}%
}
\newcommand\stacks@options@prefix{}
\define@key{stacks}{prefix}[stacks-]{%
\renewcommand\stacks@options@prefix{#1}%
\renewcommand{\label}[1]{%
\oldlabel{\stacks@options@prefix##1}%
}%
}
\makeatother
% \end{macrocode}
\endinput