1

To work around a bug in xelatex I have to compile a tree in pdflatex. This works nicely with English words but I need Chinese words for the Chinese version. But whatever I tried was giving error messages that are uninterpretable for me. Sometimes I get conflicts with 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}

Edit: MWE without loading funny packages:

\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
    This doesn't compile. You are using 6 custom packages which we don't have. And surely you can make the document a bit more minimal? Also, how do you know that the bug in XeTeX is unfixable? – Alan Munn Apr 8 '18 at 15:56
  • sorry ... I added a better MWE. – Stefan Müller Apr 8 '18 at 16:27
  • 1
    Keeping the original example doesn't make the question clearer. Your MWE (which is still not very minimal) compiles with XeLaTeX. What's the bug with XeTeX you're trying to solve? Can you show that instead? – Alan Munn Apr 8 '18 at 16:35
  • Ok, so XeLaTeX is incompatible with some of your other packages, and pdflatex chokes on the Chinese characters? Do you need extensive use of Chinese characters, or just for an example or two? – goodmami Apr 8 '18 at 16:53
  • 1
    If you use \usepackage{luatexja-fontspec}\setmainjfont{SimSun} the document will also work with LuaLaTeX, which, as noted in the comments to the AVM/linking question, solved that problem too. – Alan Munn Apr 8 '18 at 21:12
4

The reason your Chinese example doesn't work with pdfLaTeX is because your \gettext parsing macros can't deal with the way the Chinese characters are encoded in the input file. To preserve those macros you really need to use an engine that uses native UTF-8 input like XeLaTeX or LuaLaTeX.

As noted in the comments to the linked question Typesetting trees and connecting nodes and subnodes within AVMs in forest LuaLaTeX doesn't have any trouble with the connecting nodes problem, even though XeLaTeX does. This means that you can use a LuaTeX solution to your Chinese problem and preserve the parsing macros and arrows all at the same time. Here's your example using the luatexja-fontspec package:

\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}

output of code

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.