我一直在使用森林来制作逻辑证明树。对于我的项目,我需要将它们全部编译成一个大文件,并添加不属于树的注释。任何关于如何做到这一点的建议都将不胜感激。
作为参考,代码如下
\documentclass[tikz,border=5pt]{standalone}
\usepackage{forest}
\def\shoe{$\supset$}
\def\nee{$\mathord{\sim}$}
\def\nein{$\neg$}
\def\lub{$\lor$}
\begin{document}
\forestset{
ass/.append style={
before computing xy={l=\baselineskip},
no edge
},
}
\begin{forest}
for tree={
parent anchor=south,
child anchor=north,
align=center,
},
[\nee \exists (D^1 \& C^1), ass, name=n1
[\nee C^1 f, ass, name=n2
[\nee D^1 f, ass, name=n3
[\forall \nee (D^1 \& C^1), ass, name=n4
[\nee (D^1 f \& C^1 f), ass, name=n5
[\nee D^1 f, name=n6]
[\nee C^1 f]
]]]]] ]
\foreach \i in {1,...,6}
\node [xshift=-50pt, anchor=east] at (n\i -| n1) {\i.};
\foreach \i/\j in {1/{(premise)}, 2/{(premise)}, 3/{(negated conclusion)}, 4/{(1, QE)}, 5/{(4, UQ)}, 6/{(5, \nee \&)}}
\node [xshift=50pt, anchor=west] at (n\i -| n1) {\j};
\end{forest}
\end{document}
答案1
您可以像添加其他图表一样添加树:直接放在文本中间或作为图形。例如:
\documentclass{article}
\usepackage{forest}
\def\shoe{\ensuremath{\supset}}
\def\nee{\ensuremath{\sim}}
\def\nein{\ensuremath{\neg}}
\def\lub{\ensuremath{\lor}}
\forestset{
ass/.append style={
before computing xy={l=\baselineskip},
no edge
},
}
\begin{document}
Here is some text referring to figure \ref{fig:tree}.
\begin{figure}
\centering
\begin{forest}
for tree={
parent anchor=south,
child anchor=north,
align=center,
math content
},
[\nee \exists (D^1 \& C^1), ass, name=n1
[\nee C^1 f, ass, name=n2
[\nee D^1 f, ass, name=n3
[\forall \nee (D^1 \& C^1), ass, name=n4
[\nee (D^1 f \& C^1 f), ass, name=n5
[\nee D^1 f, name=n6]
[\nee C^1 f]
]]]]] ]
\foreach \i in {1,...,6}
\node [xshift=-50pt, anchor=east] at (n\i -| n1) {\i.};
\foreach \i/\j in {1/{(premise)}, 2/{(premise)}, 3/{(negated conclusion)}, 4/{(1, QE)}, 5/{(4, UQ)}, 6/{(5, \nee \&)}}
\node [xshift=50pt, anchor=west] at (n\i -| n1) {\j};
\end{forest}
\caption{A tree}
\label{fig:tree}
\end{figure}
\end{document}
请注意,我必须添加math content
才能编译,因此输出并不理想,但它演示了如何将其放入普通的article
。如果您不想让树木移动(浮动),请不要使用环境figure
并将它们放在文本中所需的适当位置。
或者你可以说
\documentclass{article}
\usepackage{forest,standalone}
\def\shoe{\ensuremath{\supset}}
\def\nee{\ensuremath{\sim}}
\def\nein{\ensuremath{\neg}}
\def\lub{\ensuremath{\lor}}
\forestset{
ass/.append style={
before computing xy={l=\baselineskip},
no edge
},
}
\begin{document}
Some text and now a tree:
\input{tree1}% if tree1.tex is the first tree
\begin{figure}
\input{tree2}
\caption{Tree 2}\label{fig:tree2}
\end{figure}
Some more text.
\end{document}
然后您不必触碰现有的树文件或乱七八糟地复制粘贴。
编辑
这是使用第二种方法的正确示例。(请注意,一棵树在环境中figure
,而另一棵树不在。这只是为了说明:我不推荐这样做。如果你确实混合了它们,你应该使用capt-of
或caption
标题来一致地标记非浮动树。)
假设tree1.tex
包含:
\documentclass[tikz,border=5pt,multi]{standalone}
\usepackage{prooftrees}
\standaloneenv{forest}
\newcommand*{\shoe}{\ensuremath{\supset}}
\newcommand*{\nee}{\ensuremath{\mathord{\sim}}}
\newcommand*{\nein}{\ensuremath{\mathord{\neg}}}
\newcommand*{\lub}{\ensuremath{\lor}}
\newcommand*{\lamp}{\ensuremath{\mathbin{\&}}}
\begin{document}
\begin{forest}
proof tree,
for tree={math content},
[, phantom
[\nee \exists (D^1 \lamp C^1), just=(premise)
[\nee C^1 f, just=(premise)
[\nee D^1 f, just=(negated conclusion)
[\forall \nee (D^1 \lamp C^1), just={(1, QE)}
[\nee (D^1 f \lamp C^1 f), just={(4, UQ)}
[\nee D^1 f, just={(5, \nee \lamp)}
]
[\nee C^1 f
]
]
]
]
]
]
]
\end{forest}
\end{document}
并tree2.tex
包含:
\documentclass[tikz,border=5pt,multi]{standalone}
\usepackage{prooftrees}
\usepackage{amssymb}
\usepackage{mathtools,turnstile}
\newcommand*{\tnot}{\ensuremath{\mathord{\sim}}}
\begin{document}
\begin{forest}
proof tree,
[{$(\exists x)(\forall y)(Py \equiv x = y) \vdash (\exists x)((\forall y)(Py \supset x = y) \,\&\, Px)$}
[{$(\exists x)(\forall y)(Py \equiv x = y)\ \checkmark a$}, just={Premise}
[{$\tnot (\exists x)((\forall y)(Py \supset x = y) \,\&\, Px)\ \backslash a$}, just={Conclusion negated}
[{$(\forall y)(Py \equiv a = y)\ \backslash a,b$}, just={From 1}
[{$\tnot ((\forall y)(Py \supset a = y) \,\&\, Pa)\ \checkmark$}, just={From 2}
[{$Pa \equiv a = a\ \checkmark$}, just={From 3}
[{$Pa$}, just={From 5}
[{$a = a$}, just={From 5}
[{$\tnot (\forall y)(Py \supset a = y)\ \checkmark b$}, just={From 4}
[{$\tnot (Pb \supset a = b)\ \checkmark$}, just={From 8}
[{$Pb$}, just={From 9}
[{$a \neq b$}, just={From 9}
[{$Pb \equiv a = b\ \checkmark$}, just={From 3}
[{$Pb$}, just={From 12}
[{$a = b$}, just={From 12}
[{$a \neq a$}, just={From 11,14}, close
]
]
]
[{$\tnot Pb$}
[{$a \neq b$}, close
]
]
]
]
]
]
]
[{$\tnot Pa$}, close
]
]
]
[{$\tnot Pa$}
[{$a \neq a$}, close
]
]
]
]
]
]
]
]
\end{forest}
\end{document}
然后我们可以写:
\documentclass{article}
\usepackage{prooftrees,standalone,kantlipsum}
\newcommand*{\shoe}{\ensuremath{\supset}}
\newcommand*{\nee}{\ensuremath{\mathord{\sim}}}
\newcommand*{\nein}{\ensuremath{\mathord{\neg}}}
\newcommand*{\lub}{\ensuremath{\lor}}
\newcommand*{\lamp}{\ensuremath{\mathbin{\&}}}
\usepackage{amssymb}
\usepackage{mathtools,turnstile}
\newcommand*{\tnot}{\ensuremath{\mathord{\sim}}}
\begin{document}
\title{Title}
\author{Me}
\maketitle
\kant[1]
This proof is best illustrated by the following tree which is simply typeset:
\begin{center}
\emph{here}\par
\input{tree1}
\end{center}
\kant[2-3]
It is time for another tree.
See figure \ref{fig:tree2} (which is \emph{there} and \emph{not} here) for details of this problem and its solution.
\begin{figure}
\input{tree2}
\caption{A tree}
\label{fig:tree2}
\end{figure}
\kant[3]
\end{document}
创建以下文章: