diff options
author | Karl Berry <karl@freefriends.org> | 2012-07-27 18:20:22 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2012-07-27 18:20:22 +0000 |
commit | 9871682c4afc822dfb4faa1618f8fc9519769b3b (patch) | |
tree | 03ae6a4de1b9df13a2e5fd6adbddd98fbac63a0b /Master | |
parent | 046814c2c3be21e2ea67f41e2ad097120749c5e0 (diff) |
tikz-cd (18jul12)
git-svn-id: svn://tug.org/texlive/trunk@27194 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master')
-rw-r--r-- | Master/texmf-dist/doc/latex/tikz-cd/README | 2 | ||||
-rw-r--r-- | Master/texmf-dist/doc/latex/tikz-cd/tikz-cd-doc.pdf | bin | 235681 -> 242031 bytes | |||
-rw-r--r-- | Master/texmf-dist/doc/latex/tikz-cd/tikz-cd-doc.tex | 176 | ||||
-rw-r--r-- | Master/texmf-dist/tex/latex/tikz-cd/tikz-cd.sty | 372 |
4 files changed, 378 insertions, 172 deletions
diff --git a/Master/texmf-dist/doc/latex/tikz-cd/README b/Master/texmf-dist/doc/latex/tikz-cd/README index 7d45e3acce1..8bb433208bf 100644 --- a/Master/texmf-dist/doc/latex/tikz-cd/README +++ b/Master/texmf-dist/doc/latex/tikz-cd/README @@ -7,4 +7,4 @@ License: LaTeX Project Public License and/or GNU Public License. Description: This package provides a set of macros to create commutative diagrams and other kinds of mathematical pictures using tikz. It also provides a set of arrow tips that match closely those -of Computer Modern's mathematical symbols.
\ No newline at end of file +of Computer Modern's mathematical symbols. diff --git a/Master/texmf-dist/doc/latex/tikz-cd/tikz-cd-doc.pdf b/Master/texmf-dist/doc/latex/tikz-cd/tikz-cd-doc.pdf Binary files differindex c63039466ee..be9d16be63c 100644 --- a/Master/texmf-dist/doc/latex/tikz-cd/tikz-cd-doc.pdf +++ b/Master/texmf-dist/doc/latex/tikz-cd/tikz-cd-doc.pdf diff --git a/Master/texmf-dist/doc/latex/tikz-cd/tikz-cd-doc.tex b/Master/texmf-dist/doc/latex/tikz-cd/tikz-cd-doc.tex index 3acee948f03..c90e94e132d 100644 --- a/Master/texmf-dist/doc/latex/tikz-cd/tikz-cd-doc.tex +++ b/Master/texmf-dist/doc/latex/tikz-cd/tikz-cd-doc.tex @@ -237,7 +237,7 @@ \ifx\mathtest\pgfmanualemptytext% \index{#2#3@\protect\texttt{#2\protect\ #3} #4 math operators}% \index{Math operators!#2#3@\protect\texttt{#2\protect\ #3}}% - \fi% +vv \fi% \pgfmanualbody } {\end{pgfmanualentry}} @@ -1328,12 +1328,13 @@ \title{The \texttt{tikz-cd} package} \author{\normalsize Florêncio Neves\footnote{\emph{E-mail:} \href{mailto:florencioneves@gmail.com}{\texttt{florencioneves@gmail.com}}}} -\date{\normalsize Version 0.2b, of March 18, 2012} +\date{\normalsize Version 0.2c, of July 17, 2012} \tikzset{commutative diagrams/background color=graphicbackground} \newcommand{\displayarrow}[2][]{\texttt{#2} & yelds \tikz[baseline=-2.5pt] \draw[#2-#2, line width=0.0929ex, #1] (0,0) -- (1,0);} -\newcommand{\displayarrowstyle}[2][]{\texttt{#2} #1 & yelds \tikz[baseline=-2.5pt] \draw[commutative diagrams/.cd, #2] (0,0) -- (0.6,0);} +\newcommand{\displayarrowstyle}[2][]{\texttt{#2} #1 & yelds + \tikz[baseline=-\tikzcdaxisheight, line width=\tikzcdrulethickness] \draw[commutative diagrams/.cd, #2] (0,0) -- (0.6,0);} \begin{document} \maketitle @@ -1358,7 +1359,7 @@ arrows present in the Computer Modern typeface. \label{sec:basic-usage} Commutative diagrams are created with the |tikzcd| environment. Its -content describes a matrix, like the |\matrix| command in \tikzname{} +content describes a matrix, similarly to the |\matrix| command in \tikzname{} or the |align| environment in \LaTeX. Everything is typeset in math mode, but you will probably want use \texttt{tikzcd} inside an |equation| environment or inside |\[| \dots |\]|, so that the diagram is @@ -1394,7 +1395,7 @@ passed to \tikzname's |node| operator. \end{tikzcd} \end{codeexample} -An arrow can actually have an arbitrary number of labels, each one +Arrows can actually have an arbitrary number of labels, each one specified by juxtaposing |{|\meta{text}|}| or |[|\meta{options}|]{|\meta{text}|}| to the |\arrow| command. @@ -1414,7 +1415,7 @@ specifiers of the form |{|\meta{text}|}| or Thus, the diagram above can be rewritten as follows. \begin{codeexample}[] \begin{tikzcd} - A \rar{\psi} \dar[color=red] + A \drar \rar{\psi} \dar[color=red] & B \dar[][color=red]{\psi} \\ C \rar[color=red][color=blue]{\eta} & D @@ -1452,13 +1453,13 @@ corresponding option (without a ``|\|'') that can be passed to \end{codeexample} Of course, a similar effect could be achieved by directly using -\tikzname's arrow tip selection scheme (e.g., using the option -|right hook->|). However, the method more above is more appropriate, as it +\tikzname{} options (e.g., using the option +|right hook->|). However, the method above is more appropriate, as it abstracts the choice of an actual arrow tip design (see also the key \texttt{commutative diagrams/arrow style} below), and is probably also better from the mnemonic standpoint. -The following list shows all arrow styles available. +The following list shows all available arrows. {\tikzset{commutative diagrams/.cd, background color=white} \begin{quote} @@ -1574,7 +1575,7 @@ stores a set. If the key above is not initialized, then \meta{size} is presumably a dimension, and |/tikz/row sep|=\meta{size} is set. - The values of \meta{size} initially available, and their values, are + The initially available \meta{size}'s, and their values, are the following: \begin{center} \begin{tabular}{cccccc} @@ -1623,7 +1624,29 @@ too tall if the column or row separation were not set appropriately. A \arrow{ur}\arrow{dr} & \\ & C \end{tikzcd} - +\end{codeexample} + +The commands below are available only inside a |tikzcd| and are +intended to be used as arguments to |&| and |\\| when spacing +adjustments are necessary. +\begin{command}{\colsep\marg{size}} + Returns the value + stored in by the key |/tikz/commutative diagrams/column sep/|\meta{size}. +\end{command} +\begin{command}{\rowsep\marg{size}} + Returns the value + stored in by the key |/tikz/commutative diagrams/row sep/|\meta{size}. +\end{command} + +In the following example, $X$ would appear too far from the square +without any spacing adjustment. +\begin{codeexample}[] +\begin{tikzcd} + X \ar[bend right]{rdd} \ar[bend left]{rrd} \ar[dashed]{dr} + &[\colsep{small}-\colsep{normal}] & \\[\rowsep{small}-\rowsep{normal}] + & A \ar{r}\ar{d} & B \ar{d} \\ + & C \ar{r} & D +\end{tikzcd} \end{codeexample} \begin{key}{/tikz/commutative diagrams/math mode=\meta{boolean} @@ -1645,7 +1668,7 @@ too tall if the column or row separation were not set appropriately. Besides the options and styles provided by this package, there are several options defined by \tikzname{} that are useful for arrows, such -as |dashed|, |dotted| and its relatives, |line width=|\meta{dimension}, |color=|\meta{color}, +as |dashed|, |dotted|, and its relatives, |line width=|\meta{dimension}, |color=|\meta{color}, |bend right|, |bend left|, |in=|\meta{angle}, |out=|\meta{angle}, |loop|, etc. See the \pgfname{} manual~\cite{pgfman}. @@ -1690,10 +1713,12 @@ if necessary. The following example, if not particularly elegant, should be instructive. \begin{codeexample}[] +\usetikzlibrary{arrows} + \tikzset{ commutative diagrams/.cd, arrow style=tikz, - diagrams={>=open triangle 45, line width=1pt}} + diagrams={>=open triangle 45, line width=\tikzcdrulethickness}} \begin{tikzcd} A \arrow{r} \arrow{d} & B \arrow{d}\\ @@ -1706,8 +1731,7 @@ should be instructive. This style specifies at which anchor of the current node an arrow should start. The default behavior is not to specify an anchor, causing the arrow to start at the point in the boundary of the - current node closest to the destination, as explained in - \pgfname{} manual~\cite{pgfman}. + current node closest to its target. \end{key} \begin{key}{/tikz/commutative diagrams/end anchor=\meta{anchor} @@ -1743,7 +1767,7 @@ use of \texttt{end anchor} and \texttt{start anchor}. Note that, since arrows are drawn in the order they are read, some arrows may need to run ``backwards'' to achieve the desired result. -The following picture, from \cite{lenders}, illustrates this. +The following picture, adapted from \cite{lenders}, illustrates this. \begin{codeexample}[] \begin{tikzcd}[row sep=scriptsize, column sep=scriptsize] @@ -1760,6 +1784,10 @@ The following picture, from \cite{lenders}, illustrates this. under a |crossing over| arrow. \end{key} +\begin{command}{\tikzcdrulethickness} + This macro returns the value (in ex) of the math font default rule + thickness. +\end{command} \subsection{Options for labels} \label{sec:options-labels} @@ -1770,11 +1798,10 @@ labels, such as |above|, |below|, |left|, |right|, |swap| (which makes the label be placed in the opposite side to the default), |sloped|, |pos=|\meta{fraction}, |near start|, |near end|, |inner sep=|\meta{dimension}, |font=|\meta{font - command}, |text width=|\meta{dimension}, etc. See \pgfname{} manual~\cite{pgfman}. + command}, |text width=|\meta{dimension}, etc. See the \pgfname{} manual~\cite{pgfman}. \begin{stylekey}{/tikz/commutative diagrams/every label} - This style works as if it were applied to the optional argument - corresponding to each label attached to an arrow. Initially is set + This style is applied to every label produced with |\arrow|. It is initially set to the following: \begin{quote}\ttfamily{} @@ -1786,9 +1813,9 @@ to the default), |sloped|, |pos=|\meta{fraction}, |near start|, \end{stylekey} The style |auto| makes the label be placed to the left of the -arrow, understanding ``front'' as the direction the arrow points at. -The dimension |inner sep| controls the distance between the -arrow and the label. +arrow, considering ``front'' as the direction the arrow points at. +The dimension |inner sep| controls the distance between an +arrow and its labels. \begin{key}{/tikz/commutative diagrams/labels=\meta{options}} This key appends \meta{options} to the style @@ -1850,11 +1877,11 @@ commands |\arrow|, |\ar|, |\rar|, |\lar|, |\dar|, |\uar|, |\urar|, |\ular|, |\drar|, |\dlar|. Initially, \meta{paths} is empty. The command -|\arrow[|\meta{options}|]{|\meta{direction}|}| does nothing at the +|\arrow[|\meta{path options}|]{|\meta{direction}|}| does nothing at the point it is inserted, and causes the following code to be added to \meta{paths}: \begin{quote} - |\path[commutative diagrams/every arrow, |\meta{options}|] (|% + |\path[commutative diagrams/every arrow, |\meta{path options}|] (|% \meta{current node}|) to |\meta{labels}| (|\meta{target~node}|);| \end{quote} @@ -1874,15 +1901,17 @@ string \end{quote} to be appended to \meta{labels}. Dollars signs surround \meta{label text} depending on the setting \texttt{commutative diagrams/math - mode}. For the abbreviated form |\rar| (and similarly for |\dar|, + mode}. + +For the abbreviated form |\rar| (and similarly for |\dar|, |\lar|, etc.), the following are valid usages: \begin{quote} |\rar{|\meta{label text}|}|\meta{more labels},\\ - |\rar[|\meta{options}|]{|\meta{label text}|}|\meta{more labels}, or\\ - |\rar[|\meta{options}|][|\meta{label options}|]{|\meta{label + |\rar[|\meta{path options}|]{|\meta{label text}|}|\meta{more labels}, or\\ + |\rar[|\meta{path options}|][|\meta{label options}|]{|\meta{label text}|}|\meta{more labels}. \end{quote} -Their effects are entirely analogous. +Their effect is entirely analogous to the above. \subsection{Tweaking \texttt{to} paths} \label{sec:tweaking-to-paths} @@ -1891,7 +1920,7 @@ Recall that the |to| path operation used in the paths created by |\arrow| can take a number of options, as described in \S{}14.14 and \S{}51 of the \pgfname{} manual~\cite{pgfman}. In particular, the option |/tikz/to path| determines the path that is actually drawn, and -can be used to do all sorts of tweaking. +can be used to do all sorts of fiddling. \begin{codeexample}[] \begin{tikzcd} @@ -1917,13 +1946,14 @@ in a way that, in the terminology of the previous section, \subsection{The \texttt{asymmetrical rectangle} shape} \label{sec:asymm-rect-shape} -The shape \texttt{asymmetrical rectangle}, defined by this package, is +The \texttt{asymmetrical rectangle} shape, defined by this package, is very similar to the \texttt{rectangle} shape, except that its \texttt{center} anchor is not located at the geometric center of the shape, but rather right above the \texttt{base} anchor, at a distance -that can be specified by the following key: +that can be specified by the following key, which is initially set to +|\tikzcdaxisheight|. -\begin{key}{/tikz/commutative diagrams/center shift=\meta{dimension} (initially 0.575ex)} +\begin{key}{/tikz/commutative diagrams/center shift=\meta{dimension}} \end{key} The picture below shows some of the available anchors. All anchors @@ -1933,8 +1963,8 @@ the numerical anchors. The anchors \texttt{real center}, \texttt{real west} and \texttt{real east} agree with \texttt{rectangle}'s \texttt{center}, \texttt{west} and \texttt{east}. -\begin{center} - \begin{tikzpicture}\Huge +\begin{center}\Huge + \begin{tikzpicture} \node[name=s,shape=asymmetrical rectangle,shape example] {Asymmetrical rectangle\vrule width 1pt height 2cm}; \foreach \anchor/\placement in {north west/above left, north/above, north @@ -1949,13 +1979,17 @@ the numerical anchors. The anchors \texttt{real center}, \texttt{real This shape is used in the matrix cells inside the \texttt{tikzcd} environment to ensure arrows between nodes in the same row are drawn -horizontally. Roughly speaking, when \tikzname{} draws a path between +horizontally. When \tikzname{} draws a path between two nodes, it chooses endpoints lying on their borders in such a way -that the path points towards the \texttt{center} of those nodes. With +that the path points towards the \texttt{center} of these nodes. With the \texttt{rectangle} shape, the anchor \texttt{center} lies halfway between two nonadjacent vertices and therefore its position depends on the height and depth of the text. +\begin{command}{\tikzcdaxisheight} + This macro returns the value (in ex) of the math font axis height. +\end{command} + \subsection{Drawing diagrams directly with Ti\emph{k}Z} \label{sec:draw-diagr-directly} @@ -2001,10 +2035,9 @@ how this can be done (the second one is adapted from \cite{milne}). The naming scheme of the Computer Modern-like arrow tips provided by this package parallels that of \pgfname's |arrows| library, documented -in \S{}23 of \pgfname{} manual~\cite{pgfman}. To match the Computer Modern +in \S{}23 of the \pgfname{} manual~\cite{pgfman}. To match the Computer Modern typeface at size 10\,pt, line width should be set to 0.4\,pt; for -larger font sizes, scale this parameter accordingly, or use the esoteric -figure 0.0929\,ex. +larger font sizes, scale this parameter accordingly, or use the macro |\tikzcdrulethickness|. Notice that by using the mechanism explained in \S\ref{sec:changing-arrow-tips}, it is not necessary, and in fact not @@ -2012,7 +2045,7 @@ advisable, to directly use the arrow tips listed in this section when creating diagrams with |tikzcd|. Incidentally, \tikzname's original |to| arrow tip seems to be based on -the pre-1992 version of Computer Modern which, in spite of the +the pre-1992 version of Computer Modern which, in spite of its author's wish \cite{knuth}, can still be found in many systems. \TeX{}Live, for instance, distributed the old version up until 2007 or 2008. Therefore, an up-to-date \TeX{} distribution may be necessary @@ -2042,7 +2075,6 @@ to get matching arrows in formulas and diagrams. \displayarrow{cm right hook}\\ \end{tabular} - \item[Double arrow tips]\ \\ \begin{tabular}{ll} \displayarrow{cm double to}\\ @@ -2058,29 +2090,67 @@ to get matching arrows in formulas and diagrams. \end{tabular} \end{description} -% \section{Some examples} -% \label{sec:some-examples} +\section{Font arrow tips} +\label{sec:font-arrow-tips} +{\it This is an experimental feature. It may be modified, moved + elsewhere or even removed in the future, and it may conflict with + future versions of \pgfname.} + +As an attempt to provide a general solution to the problem of having +matching arrow tips in text and in pictures, this feature produces +arrow tips that consist of (pieces of) characters carefully placed at +the endpoints of a path. To activate it in |tikzcd| diagrams, use +\begin{center} + |\tikzset{commutative diagrams/arrow style=math font}|. +\end{center} +It is also necessary to load |amssymb| or some other package defining +the symbols corresponding to the arrow tips you want to use. + +The above option also makes arrow tips named |math to|, \texttt{math + to reversed}, \texttt{math cap}, \texttt{math \char`\|}, |math o|, +\texttt{math implies}, |math implies cap|, |math left hook|, \texttt{math +right hook}, \texttt{math double to}, |math left to|, and \texttt{math right +to} available for use in \tikzname{} pictures in the usual way. These +tips do not scale with the line width, but their size depends on the +currently selected font size, so you will probably want to set +\texttt{line width=}|\tikzcdrulethickness| when using them. It is +possible to define more arrows or tweak the existing ones. Look into +the source code of this package if you are interested. (And let me +know what you think!) + +The transition between a line and the arrow tip may be visible with some +document viewers and printers, as you may notice from the picture +below. When using \pdf\TeX{} (or Lua\TeX) with \pdf{} output, a +measure is taken to alleviate this. +\begin{center}\tikzset{commutative diagrams/enable font arrows} + \pdf\TeX{} \tikz[baseline=-\tikzcdaxisheight] + \draw[math cap-math to, line width=\tikzcdrulethickness] (0,0) -- (1,0); + \hspace{1cm} + Other \TeX{} engines + \makeatletter\def\tikzcd@arrowset{\tikzcd@arrowset@generic}\makeatother + \tikz[baseline=-\tikzcdaxisheight] + \draw[math cap-math to,line width=\tikzcdrulethickness] (0,0) -- (1,0); +\end{center} -% \begin{codeexample}[] -% \begin{tikzcd}[row sep=small] -% H^i(A) \rar & H^i(B) \rar & H^i(C) \arrow[out=0, in=180]{dll}\\ -% H^{i+1}(A) \rar & H^{i+1}(B) \rar & H^{i+1}(C) -% \end{tikzcd} -% \end{codeexample} +I don't know of any automatic way of determining the distance between +the lines in a $\Rightarrow$, +so this parameter has to be entered manually via the key +\texttt{/tikz/commutative diagrams/font arrows/double distance} if you +want to use double lines. \section{Change history} \label{sec:change-history} \begin{description} +\item[Version 0.2c] (July 2012) Added |\tikzcdrulethickness|, + |\tikzcdaxisheight|, |\colsep|, |\rowsep|. Added experimental font arrows. \item[Version 0.2b] (March 2012) Added \texttt{asymetrical rectangle} shape. \item[Version 0.2a] (December 2011) - \begin{itemize} - \item Option |/tikz/commutative diagrams/path operation| removed + Option |/tikz/commutative diagrams/path operation| removed in favor of direct use of |/tikz/to path|. - \item Double lines with |tikz| arrow style now use \texttt{double + Double lines with |tikz| arrow style now use \texttt{double equal sign distance}. - \end{itemize} \item[Version 0.2] (October 2011) Several changes. \item[Version 0.1] (September 2011) Preliminary release. \end{description} diff --git a/Master/texmf-dist/tex/latex/tikz-cd/tikz-cd.sty b/Master/texmf-dist/tex/latex/tikz-cd/tikz-cd.sty index bd5202c82d4..ff9eeabdbd4 100644 --- a/Master/texmf-dist/tex/latex/tikz-cd/tikz-cd.sty +++ b/Master/texmf-dist/tex/latex/tikz-cd/tikz-cd.sty @@ -5,21 +5,16 @@ % 1. under the LaTeX Project Public License and/or % 2. under the GNU Public License. % -\ProvidesPackage{tikz-cd}[2012/03/18 v0.2b Commutative diagrams with tikz.] +\ProvidesPackage{tikz-cd}[2012/07/17 v0.2c Commutative diagrams with tikz.] \RequirePackage{tikz} +\AtBeginDocument{% \fontdimen's can't be read reliably inside a tikzpicture + \setbox\pgfutil@tempboxa\hbox{$ $}% + \pgfmathparse{\the\fontdimen8\textfont3/1ex}\edef\tikzcdrulethickness{\pgfmathresult ex}% + \pgfmathparse{\the\fontdimen22\textfont2/1ex}\edef\tikzcdaxisheight{\pgfmathresult ex}} \usetikzlibrary{matrix} -\usepgflibrary{arrows} -\usetikzlibrary{decorations.pathmorphing} - -\newtoks\tikzcd@temptoksa -\newtoks\tikzcd@temptoksb -\newtoks\tikzcd@temptoksc \newif\iftikzcd@mathmode - -\newcount\tikzcd@currcol -\newcount\tikzcd@currrow \newcount\tikzcd@targetrow \newcount\tikzcd@targetcol @@ -58,13 +53,36 @@ \else\def\tikzcd@targetanchor{.#1}\fi}, arrow style/.is choice} +% generic arrow tip selection styles +\pgfqkeys{/tikz/commutative diagrams}{ + dashrightarrow/.style={/tikz/commutative diagrams/.cd,rightarrow,dashed}, + dashleftarrow/.style={/tikz/commutative diagrams/.cd,leftarrow,dashed}, + rightsquigarrow/.style={ + /tikz/commutative diagrams/.cd,rightarrow,squiggly}, + leftsquigarrow/.style={/tikz/commutative diagrams/.cd,leftarrow,squiggly}, + leftrightsquigarrow/.style={ + /tikz/commutative diagrams/.cd,leftrightarrow,squiggly}, + squiggly/.code={% + \expandafter\ifx\csname tikz@library@decorations.pathmorphing@loaded\endcsname\pgfutil@empty% + \else\PackageError{tikz-cd}{To use squiggly arrows, include % + \protect\usetikzlibrary{decorations.pathmorphing} in the document preamble}{}\fi}, + squiggly/.append style={ + decorate, + decoration={ + zigzag, + segment length=4, + amplitude=.9, + post=lineto, post length=2pt, + pre=lineto, pre length=2pt}}} + % The Computer Modern arrow style -\pgfkeys{/tikz/commutative diagrams/arrow style/computer modern/.style={ +\pgfqkeys{/tikz/commutative diagrams/arrow style}{ + computer modern/.style={ /tikz/commutative diagrams/.cd, default arrow/.style={ /tikz/line join=round, /tikz/arrows=cm cap-cm to, - /tikz/line width=0.0929ex}, + /tikz/line width=\tikzcdrulethickness}, rightarrow/.style={/tikz/arrows=cm cap-cm to}, Rightarrow/.style={ /tikz/arrows=cm implies cap-cm implies, @@ -84,17 +102,10 @@ rightharpoondown/.style={/tikz/arrows=cm cap-cm right to}, leftharpoonup/.style={/tikz/arrows=cm right to-cm cap}, leftharpoondown/.style={/tikz/arrows=cm left to-cm cap}, - dashrightarrow/.style={/tikz/commutative diagrams/.cd,rightarrow,dashed}, - dashleftarrow/.style={/tikz/commutative diagrams/.cd,leftarrow,dashed}, rightarrowtail/.style={/tikz/arrows=cm to reversed-cm to}, leftarrowtail/.style={/tikz/arrows=cm to-cm to reversed}, twoheadrightarrow/.style={/tikz/arrows=cm cap-cm double to}, twoheadleftarrow/.style={/tikz/arrows=cm double to-cm cap}, - rightsquigarrow/.style={ - /tikz/commutative diagrams/.cd,rightarrow,squiggly}, - leftsquigarrow/.style={/tikz/commutative diagrams/.cd,leftarrow,squiggly}, - leftrightsquigarrow/.style={ - /tikz/commutative diagrams/.cd,leftrightarrow,squiggly}, equals/.style={ /tikz/arrows=cm implies cap-cm implies cap, /tikz/commutative diagrams/double line}, @@ -102,22 +113,18 @@ hook/.code={\pgfsetarrowsstart{cm right hook}}, two heads/.code={\pgfsetarrowsend{cm double to}}, tail/.code={\pgfsetarrowsstart{cm to reversed}}, - squiggly/.style={ - %http://tex.stackexchange.com/questions/12678/ - decorate, - decoration={ - zigzag, - segment length=4, - amplitude=.9, - post=lineto, post length=2pt, - pre=lineto, pre length=2pt}}, double line/.style={ /tikz/double=\pgfkeysvalueof{/tikz/commutative diagrams/background color}, /tikz/double distance=3.643\pgflinewidth}, dashed/.style={/tikz/densely dashed}}} % The tikz arrow style -\pgfkeys{/tikz/commutative diagrams/arrow style/tikz/.style={ +\pgfqkeys{/tikz/commutative diagrams/arrow style}{ + tikz/.code={% + \expandafter\ifx\csname tikz@library@arrows@loaded\endcsname\pgfutil@empty% + \else\PackageError{tikz-cd}{To use the `tikz' arrow style, include % + \protect\usetikzlibrary{arrows} in the document preamble}{}\fi}, + tikz/.append style={ /tikz/commutative diagrams/.cd, default arrow/.style={/tikz/arrows=->}, rightarrow/.style={/tikz/arrows=->}, @@ -139,24 +146,10 @@ rightharpoondown/.style={/tikz/arrows=-right to}, leftharpoonup/.style={/tikz/arrows=right to-}, leftharpoondown/.style={/tikz/arrows=left to-}, - dashrightarrow/.style={/tikz/commutative diagrams/.cd,rightarrow,dashed}, - dashleftarrow/.style={/tikz/commutative diagrams/.cd,leftarrow,dashed}, rightarrowtail/.style={/tikz/arrows=>->}, leftarrowtail/.style={/tikz/arrows=<-<}, twoheadrightarrow/.style={/tikz/arrows=->>}, twoheadleftarrow/.style={/tikz/arrows=<<-}, %>> - rightsquigarrow/.style={ - /tikz/commutative diagrams/.cd, - rightarrow, - squiggly}, - leftsquigarrow/.style={ - /tikz/commutative diagrams/.cd, - leftarrow, - squiggly}, - leftrightsquigarrow/.style={ - /tikz/commutative diagrams/.cd, - leftrightarrow, - squiggly}, equals/.style={ /tikz/arrows=-, /tikz/commutative diagrams/double line}, @@ -166,20 +159,10 @@ \pgfsetarrowsend{\csname tikz@special@arrow@end>>\endcsname}}, tail/.code={ \pgfsetarrowsstart{\csname tikz@special@arrow@start>\endcsname}}, - squiggly/.style={ - %http://tex.stackexchange.com/questions/12678/ - decorate, - decoration={ - zigzag, - segment length=4, - amplitude=.9, - post=lineto, post length=2pt, - pre=lineto, pre length=2pt}}, dashed/.style={/tikz/dashed}, double line/.style={ /tikz/double equal sign distance, - /tikz/double=% - \pgfkeysvalueof{/tikz/commutative diagrams/background color}}}} + /tikz/double=\pgfkeysvalueof{/tikz/commutative diagrams/background color}}}} % Default settings \pgfqkeys{/tikz/commutative diagrams}{ @@ -199,7 +182,7 @@ column sep=normal, /tikz/baseline=0pt}, math mode=true, - center shift/.initial=0.575ex, + center shift/.initial=\tikzcdaxisheight, row sep/huge/.initial=10ex, row sep/large/.initial=7.5ex, row sep/normal/.initial=5ex, @@ -276,73 +259,60 @@ \pgf@process{\pgf@marshal}% \advance\pgf@x by\pgf@xa% \advance\pgf@y by\pgfutil@tempdima% - } -} + }% +}% % Branch depending on whether the next character is [, { or none of those. \def\tikzcd@threefold#1#2#3{% - \def\tikzcd@tempa{#1}% - \def\tikzcd@tempb{#2}% - \def\tikzcd@tempc{#3}% - \futurelet\next\tikzcd@@threefold} + \def\tikzcd@tempa{#1}% + \def\tikzcd@tempb{#2}% + \def\tikzcd@tempc{#3}% + \futurelet\next\tikzcd@@threefold} + \def\tikzcd@@threefold{% - \ifx[\next\let\tikzcd@tempd\tikzcd@tempa% - \else\ifx\bgroup\next\let\tikzcd@tempd\tikzcd@tempb% - \else\let\tikzcd@tempd\tikzcd@tempc\fi\fi% - \tikzcd@tempd} + \ifx[\next\let\tikzcd@tempc\tikzcd@tempa% + \else\ifx\bgroup\next\let\tikzcd@tempc\tikzcd@tempb\fi\fi% + \tikzcd@tempc} %The arrow commands -\def\tikzcd@arrow{% - \tikzcd@targetrow\tikzcd@currrow% - \tikzcd@targetcol\tikzcd@currcol% - \tikzcd@threefold{\tikzcd@ar@getdir}{\tikzcd@ar@getdir[]}{}} +\def\tikzcd@arrow{\tikzcd@threefold{\tikzcd@ar@getdir}{\tikzcd@ar@getdir[]}{}} \def\tikzcd@ar@getdir[#1]#2{% - \tikzcd@temptoksa{\path[/tikz/commutative diagrams/every arrow,#1]}% + \tikzcd@targetrow\pgfmatrixcurrentrow% + \tikzcd@targetcol\pgfmatrixcurrentcolumn% \tikzcd@parse#2\relax% - \tikzcd@temptoksb{}% this will store the labels + \toks@\expandafter{\tikzcd@savedpaths\path[/tikz/commutative diagrams/every arrow,#1]}% + \global\edef\tikzcd@savedpaths{\the\toks@% + (\tikzmatrixname-\the\pgfmatrixcurrentrow-\the\pgfmatrixcurrentcolumn% + \noexpand\tikzcd@sourceanchor) to }% \tikzcd@threefold{\tikzcd@ar@getlabel}{\tikzcd@ar@getlabel[]}{\tikzcd@ar@final}} \def\tikzcd@ar@getlabel[#1]#2{% - \tikzcd@temptoksb\expandafter{\the\tikzcd@temptoksb % + \expandafter\def\expandafter\tikzcd@savedpaths\expandafter{\tikzcd@savedpaths% node[/tikz/commutative diagrams/every label,#1]{\tikzcd@mathmaybe{#2}}}% \tikzcd@threefold{\tikzcd@ar@getlabel}{\tikzcd@ar@getlabel[]}{\tikzcd@ar@final}} \def\tikzcd@ar@final{% - \tikzcd@temptoksc\expandafter{\tikzcd@savedpaths}% + \toks@\expandafter{\tikzcd@savedpaths} \global\edef\tikzcd@savedpaths{% - \the\tikzcd@temptoksc% the previously saved stuff - \the\tikzcd@temptoksa% the current arrow - (\tikzmatrixname-\the\tikzcd@currrow-\the\tikzcd@currcol% - \noexpand\tikzcd@sourceanchor)% - to% - \the\tikzcd@temptoksb% the current labels + \the\toks@% (\tikzmatrixname-\the\tikzcd@targetrow-\the\tikzcd@targetcol% - \noexpand\tikzcd@targetanchor);}} - -\def\tikzcd@xar#1#2{% - \tikzcd@targetrow\tikzcd@currrow% - \advance\tikzcd@targetrow by#1% - \tikzcd@targetcol\tikzcd@currcol% - \advance\tikzcd@targetcol by#2% - \tikzcd@threefold{\tikzcd@@xar}{\tikzcd@@xar[]}{\tikzcd@@xar[]}} - -\def\tikzcd@@xar[#1]{% - \tikzcd@temptoksa{\path[/tikz/commutative diagrams/every arrow,#1]}% - \tikzcd@temptoksb{}% this will store the labels - \tikzcd@threefold{\tikzcd@ar@getlabel}{\tikzcd@ar@getlabel[]}{\tikzcd@ar@final}} + \noexpand\tikzcd@targetanchor); }} + +\def\tikzcd@xar#1{\tikzcd@threefold{\tikzcd@@xar{#1}}{\tikzcd@arrow[]{#1}}{\tikzcd@arrow[]{#1}}} -% Parser for arrow direction argument -\def\tikzcd@parse#1{% - \def\tikzcd@tempa{\tikzcd@parse}% - \ifx#1r\advance\tikzcd@targetcol by1\else% - \ifx#1d\advance\tikzcd@targetrow by1\else% - \ifx#1l\advance\tikzcd@targetcol by-1\else% - \ifx#1u\advance\tikzcd@targetrow by-1\else% - \ifx#1\relax\let\tikzcd@tempa\empty% - \else\errmessage{Arrow direction argument must contain % - only the characters l, r, u or d}\fi\fi\fi\fi\fi% - \tikzcd@tempa} +\def\tikzcd@@xar#1[#2]{\tikzcd@arrow[#2]{#1}} + +\def\tikzcd@parse#1{% Parser for arrow direction argument + \def\tikzcd@tempa{\tikzcd@parse}% + \ifx#1r\advance\tikzcd@targetcol by1\else% + \ifx#1d\advance\tikzcd@targetrow by1\else% + \ifx#1l\advance\tikzcd@targetcol by-1\else% + \ifx#1u\advance\tikzcd@targetrow by-1\else% + \ifx#1\relax\let\tikzcd@tempa\empty% + \else\PackageError{tikz-cd}{Arrow direction argument must contain % + only the characters l, r, u or d}{}\fi\fi\fi\fi\fi% + \tikzcd@tempa} %The tikzcd environment \def\tikzcd{\tikzcd@threefold{\tikzcd@}{\tikzcd@[]}{\tikzcd@[]}} @@ -350,11 +320,7 @@ \def\tikzcd@[#1]{% \tikzpicture[/tikz/commutative diagrams/every diagram,#1]% \tikzcd@initialize% - \matrix[/tikz/commutative diagrams/matrix of math nodes maybe,% - /tikz/execute at begin cell=% - \tikzcd@currcol\pgfmatrixcurrentcolumn% - \tikzcd@currrow\pgfmatrixcurrentrow]% - \bgroup} + \matrix[/tikz/commutative diagrams/matrix of math nodes maybe]\bgroup} \def\endtikzcd{% \pgfmatrixendrow\egroup;% @@ -364,19 +330,21 @@ \def\tikzcd@initialize{% \def\arrow{\tikzcd@arrow}% \def\ar{\tikzcd@arrow}% - \def\rar{\tikzcd@xar{0}{1}}% - \def\lar{\tikzcd@xar{0}{-1}}% - \def\dar{\tikzcd@xar{1}{0}}% - \def\uar{\tikzcd@xar{-1}{0}}% - \def\urar{\tikzcd@xar{-1}{1}}% - \def\ular{\tikzcd@xar{-1}{-1}}% - \def\drar{\tikzcd@xar{1}{1}}% - \def\dlar{\tikzcd@xar{1}{-1}}% + \def\rar{\tikzcd@xar{r}}% + \def\lar{\tikzcd@xar{l}}% + \def\dar{\tikzcd@xar{d}}% + \def\uar{\tikzcd@xar{u}}% + \def\urar{\tikzcd@xar{ur}}% + \def\ular{\tikzcd@xar{ul}}% + \def\drar{\tikzcd@xar{dr}}% + \def\dlar{\tikzcd@xar{dl}}% + \def\rowsep##1{\pgfkeysvalueof{/tikz/commutative diagrams/row sep/##1}}% + \def\colsep##1{\pgfkeysvalueof{/tikz/commutative diagrams/column sep/##1}}% \global\let\tikzcd@savedpaths\empty} \def\tikzcd@finalize{\tikzcd@savedpaths} -\def\tikzcd@mathmaybe#1{\iftikzcd@mathmode$#1$\else#1\fi} +\def\tikzcd@mathmaybe#1{\iftikzcd@mathmode$ #1$\else#1\fi} \def\tikzcd@sep#1#2{ \pgfkeysifdefined{/tikz/commutative diagrams/#1 sep/#2}% @@ -594,4 +562,172 @@ \pgfarrowsdeclaredouble{cm double to}{cm double to}{cm to}{cm to} \pgfarrowsdeclaredouble{cm double to reversed}{cm double to reversed}{cm to reversed}{cm to reversed} -\endinput
\ No newline at end of file +%Font arrows (experimental) + +\tikzset{ + /tikz/commutative diagrams/enable font arrows/.code={% + % A little surgery on pgf's arrow selection commands + \pgfutil@ifundefined{tikzcd@orig@pgfsetarrowsend}% + {\let\tikzcd@orig@pgfsetarrowsend\pgfsetarrowsend + \let\tikzcd@orig@pgfsetarrowsstart\pgfsetarrowsstart + \def\pgfsetarrowsend##1{% + \pgfutil@ifundefined{tikzcd@arrows@cmd@##1}% + {\tikzcd@orig@pgfsetarrowsend{##1}} + {\tikzcd@arrowset{end}{##1}}}% + \def\pgfsetarrowsstart##1{% + \pgfutil@ifundefined{tikzcd@arrows@cmd@##1}% + {\tikzcd@orig@pgfsetarrowsstart{##1}} + {\tikzcd@arrowset{start}{##1}}}% + }{}}, + /tikz/commutative diagrams/font arrows/.cd, + double distance/.store in={\tikzcdfontarrowsdoubledistance}, + declare head/.code n args={4}{\tikzcd@arrowsdeclare{#1}{#2}{#3}{#4}{\iftrue}}, + declare tail/.code n args={4}{\tikzcd@arrowsdeclare{#1}{#2}{#3}{#4}{\iffalse}}, +} + +% #1 = name +% #2 = command +% #3 = axis height +% #4 = width of clip box +% #5 = \iftrue for head, \iffalse for tail +\def\tikzcd@arrowsdeclare#1#2#3#4#5{% + \expandafter\def\csname tikzcd@arrows@cmd@#1\endcsname{#2}% + \expandafter\def\csname tikzcd@arrows@ifhead@#1\endcsname{#5}% + \expandafter\def\csname tikzcd@arrows@axheight@#1\endcsname{#3}% + \expandafter\def\csname tikzcd@arrows@length@#1\endcsname{#4}} + +% Select the pdfTeX or generic backend according to pgf's setting. +% +% The generic backend uses a rectangle to clip the font glyph, and the +% pdfTeX backend uses the font glyph as the clipping path for a big +% black box. The latter method seems to trick pdf viewers and +% printers to treat the resulting arrow tip as a graphic element +% instead of text, making the transition between line and arrow tip +% less noticeable. +\def\tikzcd@tempa{pgfsys-pdftex.def} +\ifx\pgfsysdriver\tikzcd@tempa + \def\tikzcd@arrowset{\tikzcd@arrowset@pdftex} +\else + \def\tikzcd@arrowset{\tikzcd@arrowset@generic} +\fi + +% #1 `start' or `end' +% #2 arrow name +\def\tikzcd@arrowset@pdftex#1#2{% + \expandafter\def\csname pgf@#1arrow\endcsname{% + \pgfinterruptpath% + \pgf@relevantforpicturesizefalse% + \pgftransformreset% + \pgfsys@beginscope% + \pgfmathsetlengthmacro\tikzcd@len{\csname tikzcd@arrows@length@#2\endcsname}% + \setbox\pgfutil@tempboxa=\hbox{\pgfinterruptpicture % + \csname tikzcd@arrows@cmd@#2\endcsname\endpgfinterruptpicture}% + \csname tikzcd@arrows@ifhead@#2\endcsname% + \pgftransformxshift{\tikzcd@len-\wd\pgfutil@tempboxa}% + \else% + \pgftransformrotate{180}% + \pgftransformxshift{-\tikzcd@len}% + \fi% + \pgftransformyshift{-\csname tikzcd@arrows@axheight@#2\endcsname}% + \pdfliteral{7 Tr}% + \pgflowlevelsynccm\copy\pgfutil@tempboxa% + \csname tikzcd@arrows@ifhead@#2\endcsname\else% + \pgftransformxshift{\tikzcd@len-\wd\pgfutil@tempboxa}% + \fi% + \pgfpathrectangle{\pgfpoint{0pt}{-1ex}}{\pgfpoint{-\tikzcd@len}{3ex}}% + \pgfusepathqfill% + \pgfsys@endscope% + \endpgfinterruptpath}% + \expandafter\def\csname pgf@shorten@#1\endcsname{% + \pgfmathsetlength\pgf@xa{\csname tikzcd@arrows@length@#2\endcsname}% + \advance\pgf@x by\pgf@xa}}% + +% #1 `start' or `end' +% #2 arrow name +\def\tikzcd@arrowset@generic#1#2{% + \expandafter\def\csname pgf@#1arrow\endcsname{% + \pgfinterruptpath% + \pgf@relevantforpicturesizefalse% + \pgftransformreset% + \pgfsys@beginscope% + \pgfmathsetlengthmacro\tikzcd@len{\csname tikzcd@arrows@length@#2\endcsname}% + \pgfpathrectangle{\pgfpoint{0pt}{-1.5ex}}{\pgfpoint{\tikzcd@len}{3ex}}% + \pgfusepathqclip% + \csname tikzcd@arrows@ifhead@#2\endcsname% + \pgftransformxshift{\tikzcd@len}% + \else% + \pgftransformrotate{180}% + \pgftransformxshift{-\tikzcd@len}% + \fi% + \pgftransformyshift{-\csname tikzcd@arrows@axheight@#2\endcsname}% + \pgftext[\csname tikzcd@arrows@ifhead@#2\endcsname right\else left\fi,base]% + {\csname tikzcd@arrows@cmd@#2\endcsname}% + \pgfsys@endscope% + \endpgfinterruptpath}% + \expandafter\def\csname pgf@shorten@#1\endcsname{% + \pgfmathsetlength\pgf@xa{\csname tikzcd@arrows@length@#2\endcsname}% + \advance\pgf@x by\pgf@xa}}% + +% The arguments for `declare head' and `declare tail' are 1. name of +% the arrow tip, 2. TeX command corresponding to an arrow, 3. distance +% from baseline to arrow stem, 4. width of the clip box, which should +% be big enough to contain the whole tip. +\tikzset{/tikz/commutative diagrams/font arrows/.cd, + double distance={3.8\pgflinewidth}, + declare head={math to}{$\to$}{\tikzcdaxisheight}{1ex}, + declare head={math to reversed}{$\leftarrowtail$}{\tikzcdaxisheight}{1ex}, + declare tail={math cap}{$\to$}{\tikzcdaxisheight}{1ex}, + declare tail={math |}{$\mapsto$}{\tikzcdaxisheight}{1ex}, + declare head={math o}{$\multimap$}{\tikzcdaxisheight}{1.4ex}, + declare head={math implies}{$\Rightarrow$}{\tikzcdaxisheight}{1.4ex}, + declare tail={math implies cap}{$\Rightarrow$}{\tikzcdaxisheight}{1ex}, + declare head={math left hook}{$\hookleftarrow$}{\tikzcdaxisheight}{1ex}, + declare tail={math right hook}{$\hookrightarrow$}{\tikzcdaxisheight}{1ex}, + declare head={math double to}{$\twoheadrightarrow$}{\tikzcdaxisheight}{1.4ex}, + declare head={math left to}{$\rightharpoonup$}{\tikzcdaxisheight}{1ex}, + declare head={math right to}{$\rightharpoondown$}{\tikzcdaxisheight}{1ex}, +} + +% The `math font' arrow style +\pgfkeys{/tikz/commutative diagrams/arrow style/math font/.style={ + /tikz/commutative diagrams/.cd, + enable font arrows, + default arrow/.style={ + /tikz/arrows=math cap-math to, + /tikz/line width=\tikzcdrulethickness}, + rightarrow/.style={/tikz/arrows=math cap-math to}, + Rightarrow/.style={ + /tikz/arrows=math implies cap-math implies, + /tikz/commutative diagrams/double line}, + leftarrow/.style={/tikz/arrows=math to-math cap}, + Leftarrow/.style={ + /tikz/arrows=math implies-math implies cap, + /tikz/commutative diagrams/double line}, + leftrightarrow/.style={/tikz/arrows=math to-math to}, + Leftrightarrow/.style={ + /tikz/arrows=math implies-math implies, + /tikz/commutative diagrams/double line}, + mapsto/.style={/tikz/arrows=math |-math to}, + hookrightarrow/.style={/tikz/arrows=math right hook-math to}, + hookleftarrow/.style={/tikz/arrows=math to-math left hook}, + rightharpoonup/.style={/tikz/arrows=math cap-math left to}, + rightharpoondown/.style={/tikz/arrows=math cap-math right to}, + leftharpoonup/.style={/tikz/arrows=math right to-math cap}, + leftharpoondown/.style={/tikz/arrows=math left to-math cap}, + rightarrowtail/.style={/tikz/arrows=math to reversed-math to}, + leftarrowtail/.style={/tikz/arrows=math to-math to reversed}, + twoheadrightarrow/.style={/tikz/arrows=math cap-math double to}, + twoheadleftarrow/.style={/tikz/arrows=math double to-math cap}, + equals/.style={ + /tikz/arrows=math implies cap-math implies cap, + /tikz/commutative diagrams/double line}, + maps to/.code={\pgfsetarrowsstart{math |}}, + hook/.code={\pgfsetarrowsstart{math right hook}}, + two heads/.code={\pgfsetarrowsend{math double to}}, + tail/.code={\pgfsetarrowsstart{math to reversed}}, + double line/.style={ + /tikz/double=\pgfkeysvalueof{/tikz/commutative diagrams/background color}, + /tikz/double distance=\tikzcdfontarrowsdoubledistance}, + dashed/.style={/tikz/densely dashed}}} + +\endinput |