为了解决 xelatex 中的一个错误,我必须在 pdflatex 中编译一个树。这可以很好地处理英文单词,但我需要中文版本的中文单词。但无论我尝试什么,都会给出我无法解释的错误消息。有时我会遇到冲突forest
。
\documentclass{article}
\usepackage{libertine}\usepackage[libertine]{newtxmath}
\usepackage{langsci-forest-setup,makros.2e,abbrev,merkmalstruktur,dalrymple,my-xspace}
\usepackage{langsci-lgr}
\usetikzlibrary{tikzmark}
%\usepackage[whole]{bxcjkjatype} conflicts with forest
% requires xelatex
%\usepackage{xeCJK}
%\setCJKmainfont{SimSun}
\usepackage{CJKutf8}
% to set the MRSes for scope underspecification
%http://tex.stackexchange.com/questions/218417/replacing-tree-dvips-connect-nodes-in-a-tabular-environment/218458#218458
\usepackage{tcolorbox}
\tcbuselibrary{skins}
\newtcbox{\mybox}[1][]{empty,shrink tight,nobeforeafter,on line,before upper=\vphantom{gM},remember as=#1,top=2pt,bottom=2pt}
\newcommand{\mynode}[2]{\mybox[#1]{#2}}
\newcommand{\centtab}[1]{\begin{tabular}[t]{@{}c@{}}#1\end{tabular}}
\begin{document}
\thispagestyle{empty}
\begin{forest}
sm edges
[\subnode{cp}{CP}
[\centtab{(\up \textsc{df})= (\up \textsc{comp}* \textsc{gf})\\
(\up \textsc{df})=\down \\
\subnode{npobj}{NP}}
[den Apfel;\textsc{det.def} 苹果, roof]]
[\centtab{\up~=~\down\\
\subnode{cbar}{\cbar}}
[\centtab{\up~=~\down\\
\subnode{c}{C}} [verschlingt;吞食]]
[\centtab{\up~=~\down\\
\subnode{vp}{VP}}
[\centtab{(\upsp \textsc{subj}) = \down\\
\subnode{npsubj}{NP}}
[David;David]]]]]
\end{forest}\hfill
\raisebox{13em}{%
\mynode{all}{\lfgms{ pred & `VERSCHLINGEN\sliste{\lfgsubj,\lfgobj}'~~\\
subj & \mynode{fdavid}{\lfgms{ pred & `DAVID' \\
case & nom\\
}}\\
tense & PRES\\
topic & \mynode{fapple}{\lfgms{ pred & `APFEL'\\
case & acc\\
}}\\
obj & \mynode{obj}{}
}}}
\begin{tikzpicture}[overlay,remember picture]
\draw[->] (cp) to[out= 0,in=180] (all.west);
\draw[->] (cbar) to[out=10,in=180] (all.west);
\draw[->] (c) to[out=10,in=180] (all.west);
\draw[->] (vp) to[out= 0,in=180] (all.west);
\draw[->] (npsubj) to[out=15,in=200] (fdavid.west);
\draw[->] (npobj) to[out= 0,in=215] (fapple.west);
\draw (obj) to[out=0,in=0,distance=6em] (fapple.east);
\end{tikzpicture}
\end{document}
编辑:MWE 不加载有趣的包:
\documentclass{article}
\usepackage{libertine}\usepackage[libertine]{newtxmath}
\usepackage[external,linguistics]{forest}
\tikzset{external/up to date check=simple}
% for texlive: -shell-escape, for miktex -enable-write18
% All externalized graphics go go the \externaldirectory
%\tikzexternalize[prefix=external-figures/,shell escape=-shell-escape]
\tikzset{external/system call={xelatex \tikzexternalcheckshellescape -halt-on-error -interaction=batchmode -jobname "\image" "\texsource"}}
%\usepackage{morewrites}
% specification for all trees, "default preamble" appends to existing specification.
% The version with apostrophe replaces it.
\forestset{default preamble'={
for tree={align=center,parent anchor=south, child anchor=north,anchor=north,base=bottom},
% This would align trees to the baseline. We do not want this for TAG
% where several trees have to be aligned with respect to their center.
% before drawing tree={
% sort by=y,
% for min={tree}{baseline}
% }
}}
\forestset{
declare dimen={child anchor yshift}{0pt},
adjust childrens child anchors/.style={
if n children>=2{
before packing={
tempdima/.max={max_y}{children},
for children={
child anchor yshift=tempdima()-max_y()
},
}
}{}
},
default preamble={
for tree={
edge path'={(!u.parent anchor)--([yshift=\forestoption{child anchor yshift}].child anchor)},
adjust childrens child anchors
}
},
}
% http://www.texample.net/tikz/examples/borrowers-and-lenders/
\usetikzlibrary{arrows} %,positioning}
\tikzset{
%Define standard arrow tip
>=stealth'}
%% \forestset{
%% sn edges/.style={for tree={parent anchor=south, child anchor=north,align=center,base=bottom,where n children=0{tier=word}{}}},
%% background tree/.style={for tree={text opacity=0.2,draw opacity=0.2,edge={draw opacity=0.2}}}
%% }
% The following code fixes the size of triangles for examples with translations. The specification
% ",delay=with translation" at the leaves is important to make this work.
% http://tex.stackexchange.com/questions/167978/smaller-roofs-for-forest/205311#205311
\forestset{
with translation/.style={
l sep=0,inner xsep=0,
append translation/.expanded/.wrap pgfmath arg={\gettranslation{##1}}{content},
content/.expanded/.wrap pgfmath arg={\gettext{##1}}{content},
},
append translation/.style={
if={strequal("#1","")}{}{
append={[#1,no edge,inner xsep=0,inner ysep=0,outer ysep=0,
l=\baselineskip + 0.2ex,
]}
}
}
}
\def\gettext#1{\gettextA#1;;\endget}
\def\gettextA#1;#2;{\removesep#1;}
\def\gettranslation#1{\gettranslationA#1;;\endget}
\def\gettranslationA#1;#2;{\removesep#2;}
\def\removesep#1;#2\endget{#1}
% a specific style that specifies the word tier: all nodes that do not have any children
% to do: make this style default and change all other figures explicitely as is described here:
% http://tex.stackexchange.com/questions/167983/getting-rid-of-a-default-where-specification
\forestset{
sm edges/.style={for tree={parent anchor=south, child anchor=north,base=top}, % changed base=bottom
% to top since we have NP and AVM nodes and the NP has to start
% right away at the same hight as the AVM St. Mü. 18.10.2017
where n children=0{tier=word,delay=with translation}{} %,delay=with translation
}}
\usetikzlibrary{tikzmark}
%\usepackage[whole]{bxcjkjatype} conflicts with forest
% requires xelatex
%\usepackage{xeCJK}
%\setCJKmainfont{SimSun}
% \usepackage{CJKutf8}
% to set the MRSes for scope underspecification
%http://tex.stackexchange.com/questions/218417/replacing-tree-dvips-connect-nodes-in-a-tabular-environment/218458#218458
\usepackage{tcolorbox}
\tcbuselibrary{skins}
\newtcbox{\mybox}[1][]{empty,shrink tight,nobeforeafter,on line,before upper=\vphantom{gM},remember as=#1,top=2pt,bottom=2pt}
\newcommand{\mynode}[2]{\mybox[#1]{#2}}
\newcommand{\centtab}[1]{\begin{tabular}[t]{@{}c@{}}#1\end{tabular}}
\robustify\textsc
\robustify\textit
\begin{document}
\thispagestyle{empty}
\begin{forest}
sm edges
[CP
[NP
[den Apfel;\textsc{det.def} 苹果, roof]]
[C'
[C [verschlingt;吞食]]
[VP
[NP
[David;David]]]]]
\end{forest}
\end{document}
答案1
您的中文示例无法与 pdfLaTeX 配合使用的原因在于您的\gettext
解析宏无法处理输入文件中中文字符的编码方式。要保留这些宏,您确实需要使用使用原生 UTF-8 输入的引擎,例如 XeLaTeX 或 LuaLaTeX。
正如链接问题的评论中指出的那样排版树并连接森林中 AVM 内的节点和子节点LuaLaTeX 不会遇到连接节点问题,而 XeLaTeX 会。这意味着您可以使用 LuaTeX 解决方案解决中文问题,同时保留解析宏和箭头。以下是使用该luatexja-fontspec
包的示例:
\documentclass{article}
\usepackage{libertine}
\usepackage[libertine]{newtxmath}
\usepackage[external,linguistics]{forest}
\tikzset{external/up to date check=simple}
% for texlive: -shell-escape, for miktex -enable-write18
% All externalized graphics go go the \externaldirectory
%\tikzexternalize[prefix=external-figures/,shell escape=-shell-escape]
\tikzset{external/system call={lualatex \tikzexternalcheckshellescape -halt-on-error -interaction=batchmode -jobname "\image" "\texsource"}}
%\usepackage{morewrites}
% specification for all trees, "default preamble" appends to existing specification.
% The version with apostrophe replaces it.
\forestset{default preamble'={
for tree={align=center,parent anchor=south, child anchor=north,anchor=north,base=bottom},
% This would align trees to the baseline. We do not want this for TAG
% where several trees have to be aligned with respect to their center.
% before drawing tree={
% sort by=y,
% for min={tree}{baseline}
% }
}}
\forestset{
declare dimen={child anchor yshift}{0pt},
adjust childrens child anchors/.style={
if n children>=2{
before packing={
tempdima/.max={max_y}{children},
for children={
child anchor yshift=tempdima()-max_y()
},
}
}{}
},
default preamble={
for tree={
edge path'={(!u.parent anchor)--([yshift=\forestoption{child anchor yshift}].child anchor)},
adjust childrens child anchors
}
},
}
% http://www.texample.net/tikz/examples/borrowers-and-lenders/
\usetikzlibrary{arrows} %,positioning}
\tikzset{
%Define standard arrow tip
>=stealth'}
%% \forestset{
%% sn edges/.style={for tree={parent anchor=south, child anchor=north,align=center,base=bottom,where n children=0{tier=word}{}}},
%% background tree/.style={for tree={text opacity=0.2,draw opacity=0.2,edge={draw opacity=0.2}}}
%% }
% The following code fixes the size of triangles for examples with translations. The specification
% ",delay=with translation" at the leaves is important to make this work.
% http://tex.stackexchange.com/questions/167978/smaller-roofs-for-forest/205311#205311
\forestset{
with translation/.style={
l sep=0,inner xsep=0,
append translation/.expanded/.wrap pgfmath arg={\gettranslation{##1}}{content},
content/.expanded/.wrap pgfmath arg={\gettext{##1}}{content},
},
append translation/.style={
if={strequal("#1","")}{}{
append={[#1,no edge,inner xsep=0,inner ysep=0,outer ysep=0,
l=\baselineskip + 0.2ex,
]}
}
}
}
\def\gettext#1{\gettextA#1;;\endget}
\def\gettextA#1;#2;{\removesep#1;}
\def\gettranslation#1{\gettranslationA#1;;\endget}
\def\gettranslationA#1;#2;{\removesep#2;}
\def\removesep#1;#2\endget{#1}
% a specific style that specifies the word tier: all nodes that do not have any children
% to do: make this style default and change all other figures explicitely as is described here:
% http://tex.stackexchange.com/questions/167983/getting-rid-of-a-default-where-specification
\forestset{
sm edges/.style={for tree={parent anchor=south, child anchor=north,base=top}, % changed base=bottom
% to top since we have NP and AVM nodes and the NP has to start
% right away at the same hight as the AVM St. Mü. 18.10.2017
where n children=0{tier=word,delay=with translation}{} %,delay=with translation
}}
\usetikzlibrary{tikzmark}
\usepackage{luatexja-fontspec}
\setmainjfont{SimSun}
% to set the MRSes for scope underspecification
%http://tex.stackexchange.com/questions/218417/replacing-tree-dvips-connect-nodes-in-a-tabular-environment/218458#218458
\usepackage{tcolorbox}
\tcbuselibrary{skins}
\newtcbox{\mybox}[1][]{empty,shrink tight,nobeforeafter,on line,before upper=\vphantom{gM},remember as=#1,top=2pt,bottom=2pt}
\newcommand{\mynode}[2]{\mybox[#1]{#2}}
\newcommand{\centtab}[1]{\begin{tabular}[t]{@{}c@{}}#1\end{tabular}}
\robustify\textsc
\robustify\textit
\begin{document}
\thispagestyle{empty}
\begin{forest}
sm edges
[CP
[NP
[den Apfel;\textsc{det.def} 苹果, roof]]
[C'
[C [verschlingt;吞食]]
[VP
[NP
[David;David]]]]]
\end{forest}
\end{document}