6

@cfr produced an amazing forest tree that runs over several pages in this great answer. This is an amazing achievement as it effectively spreads a TikZ picture over several pages. (Of course, technically there is one tikzpicture per page, a more precise statement is that the content of a huge tikzpicture gets spread over several pages.) I am not seen any other post that achieves this.

If one looks at the result, it is obvious that some space is "wasted" as the tree is very narrow. Therefore, one may wonder if it is possible to do this in a document with two columns.

There is very similar question on this, which has an MWE to play with. The difference between this question and mine is that I am looking for a solution that uses the \twocolumn switch whereas in this question a solution using multicols was asked for. I do not provide an MWE (unless I am asked to) since this great answer already has everything in it except for the twocolumn switch.

Note that I am aware of the fact that @cfr is able to do that. The purpose of my "question" is to have a way to share this stunning code can be shared with the community. I do not want any credit for this (because I do not deserve any), so if you have votes please use them on the answer, not on my question. Notice that if are not @cfr and reading this and have a clever solution, of course I will be very much interested in it, too.

9
  • 1
    I've provided a second answer below, but I don't know if the system will tell you this. In case you're interest and it doesn't, well, there it goes.
    – cfr
    Aug 22 '18 at 3:56
  • @cfr No the system does not notify me, and I am really interested. Seems like I awarded the bounty to the wrong answer... ;-)
    – user121799
    Aug 22 '18 at 3:58
  • 1
    @Simon Why isn't a good solution to \usetikzlibrary{babel} before \setlanguage.... I don't see why that's not a good solution at all.
    – cfr
    Aug 25 '18 at 21:54
  • 1
    @Simon It is not unusual that one has to load packages in a certain order. Examples include cleveref, which wants to be loaded last. Of course, if several packages want to be loaded last, there might be an issue. ;-)
    – user121799
    Aug 26 '18 at 14:34
  • 1
    @Simon As marmot says, it is inevitable that there are going to be things which have to be done in one order rather than another. That's not specific to Polyglossia or TikZ. You might try Babel, which is less buggy than Polyglossia in general, but having to worry about the order of commands is pretty much unavoidable. (How could it not be so?) Note that you can load all your packages first in this particular case. You could also say \AtEndPreamble{\setmainlanguage{}...} and put there wherever you wished - before loading polyglossia, if you liked. (You may need to load etoolbox.)
    – cfr
    Aug 26 '18 at 19:46
5

The answer requested by marmot is given under 'Original answer' below. This answer is a little different.

The following code tries to

  1. replace more edges
  2. add 'continued' only to right hand columns
  3. work even when the tree starts/end on the same page (where text is also two-column)
  4. retain the multicols option, but without the adding significant crud to the compilation (I think)
  5. work even when one tree directly follows another (likely fragile? I got this working, but I'm not convinced I identified the root cause)

This code figures out for itself whether it is in twocolumn mode or not and, if it is, whether it is in a left or right hand column. At least, that's the theory.

Caveat emptor

updated output

% atebion: https://tex.stackexchange.com/a/44557,84,446899 addaswyd o ateb: http://tex.stackexchange.com/a/356922/ addaswyd o gwestiwn Sebastian Widz: http://tex.stackexchange.com/q/356749/ a chestiynnau Simon: https://tex.stackexchange.com/q/445199/ a marmot: https://tex.stackexchange.com/q/446759/
% gweler hefyd forest2-1-dir-tree-split-auto{4,5,6,7,8}.tex
\documentclass[a4paper,12pt]{article}
\usepackage{geometry,kantlipsum,multicol}% geometry or similar is needed for correct A4 layout
\usepackage[edges]{forest}
% addaswyd o gôd Sašo Živanović: http://tex.stackexchange.com/a/296771/
\def\hiddenparcommand{\par}
\newcommand\otherhiddenparcommand{\par\noindent}
\newcommand\hiddencommacommand{, }
\makeatletter
\forestset{%
  declare keylist register={split here ids},% the list of nodes to split the tree at
  split here ids={},
  declare keylist register={split here interjects},% the list of comments to put in between the tree parts
  split here interjects={},
  declare toks register=split here toks,
  declare dimen register=tmpdima,
  tmpdima'=0pt,
  declare dimen register=tmpdimb,
  tmpdimb'=0pt,
  declare dimen register=tmpdimc,
  tmpdimc'=0pt,
  declare dimen register=tmpdimd,
  tmpdimd'=\textheight,
  declare boolean register={multicols},
  not multicols,
  declare boolean register={two column},
  not two column,
  declare boolean register={first column},
  not first column,
  declare count={split parent id}{0},
  declare count={split descendant id}{0},
  declare count register={split parent id count},
  split parent id count'=0,
  declare toks={split descendant}{},
  declare toks register={split dir tree cont},
  split dir tree cont=continued,
  declare long step={current and preceding parents}{}{filter={current and preceding nodes}{>OO={n children}{n children}}},
  declare keylist={splitter list}{},
  to widest/.style={
    tikz+={\path (\forestregister{tempdima}, \forestoption{y}) -- (\forestregister{tempdimb}, \forestoption{y});},
  },
  hide commas/.style={%
    split here toks+={\hiddencommacommand},
    split here toks+/.option=#1,
  },
  split dir tree pre/.style={%
    label={[text=gray, anchor=north, font=\scriptsize]below:{[cont.]}{}},
    tempcountd/.option=id,
    temptoksc/.option=name,
    for Nodewalk={on invalid=fake}{do until={ > O_ O_ =!=|  {split descendant id}{0} {level}{0}  }{split descendant id/.register=tempcountd, split descendant/.register=temptoksc, previous node}}{},
  },
  split dir tree post/.style={%
    label={[font=\scriptsize, anchor=south, text=gray]above:{[cont.]}{}},
    tikz+/.process={% this draws an edge to the first node after a break
      OOOw+nw3  {edge}{edge label}{id}{##1+1}%
      {%
        \path [##1] (!u.parent anchor |- .north) ++(\forestregister{folder indent},1ex) coordinate (before ##3) |- (.child anchor)##2 ;
      }%
    },
  },
  split dir tree/.code={%
    \hskip0pt\otherhiddenparcommand
    \forestset{%
      for tree={
        folder,
        grow'=0,
        edge path={},
      },
      tikz+/.process={Ow{id}{\path (.parent anchor) coordinate (before ##1);}},
      draw tree stage/.style={
        for root'={
          tempdima/.min={%
            >OOw2+d{x}{min x}{####1+####2}%
          }{tree},
          tempdimb/.max={%
            >OOw2+d{x}{max x}{####1+####2}%
          }{tree},
          for tree={%
            to widest,
          },
        },
        tempcountb'=-1,
        do until={%
          strequal((split_here_ids),"")
        }{%
          tempkeylistb'={},
          tempkeylista'={},
          split register={split here ids}{,}{tempcounta,tempkeylistb+},
          split register={split here interjects}{,}{temptoksa,tempkeylista+},
          split here ids'/.register=tempkeylistb,
          split here interjects'/.register=tempkeylista,
        % Sašo Živanović: http://chat.stackexchange.com/transcript/message/28484520#28484520
         for nodewalk={%
           draw tree processing order/.style={%
             filter={tree}{> ORw+n< OR> & {id}{tempcounta}{########1+1}{id}{tempcountb}}%
           }%
         }{},
          for root'={draw tree},
          TeX/.process={Rw{temptoksa}{\otherhiddenparcommand ####1\hiddenparcommand}},
          tempcountb'/.register=tempcounta,
        },
        for nodewalk={%
          draw tree processing order/.style={%
            filter={tree}{>OR>{id}{tempcountb}}%west
          }%
        }{},
        for root'={draw tree},
      },
    }%
  },
  split dir here auto/.style={%
    split dir tree pre,
    !next node.split dir tree post,
    split here ids+/.option=id,
    split={#1}{,}{split here toks,hide commas},
    split here interjects/.register=split here toks,
  },
  split dir tree auto/.style={%
    split dir tree,
    TeX={%
      \if@twocolumn\forestset{two column}\else\forestset{not two column}\fi
    },
    before drawing tree={%
%       for tree={tikz+/.process={Ow{id}{\node [blue] at (.child anchor) {##1};}}},
      tempdima/.max={y}{tree},
      tempdimc/.register=tempdima,
      tempdimd/.min={y}{tree},
      tempdima-/.register=tempdimd, % cyfanswm yr y sy'n angen
      tempdimb'=\textheight,
      tmpdima'=10ex,
      not tempboola,
      tempcounta/.option=id,
      temptoksb/.option=name,
      not tempboolb,
      tempboolc,
      if two column={
        tmpdimc/.process={dd>?d {\pagetotal}{\@colht}{\pagetotal-\@colht}{\pagetotal}},
        TeX={\if@firstcolumn\ifdim\pagetotal>\@colht\forestset{not first column}\else\forestset{first column}\fi\else\ifdim\pagetotal>\@colht\forestset{first column}\else\forestset{not first column}\fi\fi},
      }{
        if multicols={tmpdimc=\textheight-\page@free+\multicolsep, tempboola, split dir tree cont=\relax}{tmpdimc'=\pagetotal},
      },
      while={%
        >RR>{tempdima}{tempdimb}%
      }{%
        for nodewalk={%
          id/.register=tempcounta,
          temptoksb/.option=name,
          until={%
            > ROw2+d RRRw3+d > {tempdimc}{y}{##1-##2} {tmpdima}{tmpdimc}{tmpdimd}{##3-##2-##1}%
          }{next node, split parent id/.register=tempcounta, split parent id+'=1},
          previous node,
          if={>Pn={forestloopcount}{1}}{tempcounta/.option=id, temptoksd/.option=name, for current and preceding nodes={split descendant id/.register=tempcounta, split descendant/.register=temptoksd,}}{},
          if two column={if first column={split dir tree cont=\relax, not first column}{split dir tree cont=continued, first column}}{},
          split dir here auto/.register=split dir tree cont,
          next node,
          split parent id/.option=id,
          split parent id+'=1,
          tempcounta/.option=id,
          split parent id count/.option=split parent id,
          tempdima/.option=y,
          tempdimc/.register=tempdima,
          tempdima-/.register=tempdimd,
          tmpdima'=15ex,
          if tempboola={not tempboola}{tmpdimc'=0pt},
          if={>RR&{multicols}{tempboolc}}{% 1 for odd (except first); 0 for evens; split dir tree cont changes next iteration i.e. 1 for evens; 0 for odds
            if tempboolb={
              not tempboolb, split dir tree cont=\relax,
              if={> RR_w3+dRw+d< {tempdima}{tmpdima}{10ex}{##1+##2+##3}{tempdimb}{##1+##1} }{
                not tempboolc,
                split dir tree cont=\relax,
                tempdimb/.process={Rw+d{tempdima}{##1/2}},
                tmpdimd/.register=tempdimb,
                tempdimb+/.register=tmpdima,
                tmpdimd+/.process={Rw+d{tmpdima}{##1/3}},
                tmpdima'=0pt,
              }{},
            }{
              tempboolb, split dir tree cont=continued,
            },
          }{},
        }{},
      },
      where level=0{}{
        if split parent id=0{split parent id/.register=split parent id count}{},
        if={ > OOw+n< {!u.id}{split parent id}{##1-1} }{
          tikz+/.process={ OOOw3 {edge}{edge label}{split parent id} {\path [##1] (!u.parent anchor |- before ##3) ++(\forestregister{folder indent},0pt) |- (.child anchor)##2;}}
        }{
          if={ > OOw+n= {id}{split parent id}{##1-1} }{}{
            tikz+/.process={ OOw2 {edge}{edge label} {\path [##1] (!u.parent anchor) ++(\forestregister{folder indent},0pt) |- (.child anchor)##2;}}
          },
        },
      },
      where n children=0{}{ 
        if={ > OO> {!l.id}{split descendant id} }{
          tikz+/.process={ OOw2 {edge}{split descendant} { \path [##1] (.parent anchor) ++(\forestregister{folder indent},0pt) coordinate (a) -- (a |- ##2.parent anchor) -- ++(0pt,-1ex);  }
          },
        }{},
      },
      split register={split here ids}{,}{splitter split},
    },
  },
  splitter split/.style={
    for nodewalk={id=#1}{
      tempcounta/.option=id,
      tempcountc/.option=split parent id,
      tempkeylista'=,
      for filter={current and preceding nodes}{>O_>{n children}{0}}{
        if={> OR > OR < & {!l.id}{tempcounta} {id}{tempcountc}  }{
          tempkeylista+/.option=name,
        }{},
      },
      splitter list/.register=tempkeylista,
      tikz+/.process={ 
        OOw2{split parent id}{edge}{
          \edef\tempa{\foresteoption{splitter list}}
          \foreach \i in \tempa {\path [##2] (\i.parent anchor |- before ##1) ++(\forestregister{folder indent},0pt)  coordinate (b) -- (.parent anchor -| b) -- ++(0,-1ex); }
        }
      },
    },
    if nodewalk valid={next}{temptoksa/.option=!next.name}{temptoksa'={}},
  },
}
\makeatother
\begin{document}
\twocolumn
\kant[1-2]


\begin{forest}
  split dir tree auto,
  [XYZ[XYZ[XYZ[XYZ[XYZ]]][XYZ[XYZ[XYZ]]][XYZ[XYZ[XYZ][XYZ][XYZ][XYZ][XYZ][XYZ][XYZ]][XYZ[XYZ][XYZ][XYZ][XYZ][XYZ]][XYZ[XYZ]][XYZ[XYZ][XYZ]]][XYZ[XYZ[XYZ][XYZ]]][XYZ[XYZ[XYZ][XYZ][XYZ][XYZ][XYZ][XYZ]][XYZ[XYZ]][XYZ[XYZ][XYZ][XYZ]]][XYZ[XYZ[XYZ]]][XYZ[XYZ[XYZ][XYZ][XYZ]]][XYZ[XYZ[XYZ][XYZ][XYZ][XYZ][XYZ][XYZ]]][XYZ[XYZ[XYZ][XYZ][XYZ][XYZ][XYZ][XYZ][XYZ][XYZ][XYZ][XYZ][XYZ][XYZ][XYZ][XYZ][XYZ][XYZ][XYZ][XYZ][XYZ]][XYZ[XYZ][XYZ]][XYZ[XYZ][XYZ][XYZ]]][XYZ[XYZ[XYZ][XYZ][XYZ][XYZ][XYZ][XYZ][XYZ]][XYZ[XYZ]][XYZ[XYZ]]][XYZ[XYZ[XYZ][XYZ][XYZ][XYZ][XYZ][XYZ][XYZ]][XYZ[XYZ]]][XYZ[XYZ[XYZ][XYZ]]][XYZ[XYZ[XYZ][XYZ][XYZ][XYZ][XYZ][XYZ][XYZ][XYZ][XYZ][XYZ][XYZ][XYZ][XYZ][XYZ][XYZ][XYZ]][XYZ[XYZ]]][XYZ[XYZ[XYZ][XYZ][XYZ][XYZ][XYZ][XYZ][XYZ][XYZ][XYZ][XYZ]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.XYZ]][2.XYZ[3.XYZ][3.XYZ][3.XYZ][3.XYZ]]][1.XYZ[2.XYZ][2.XYZ][2.XYZ][2.XYZ][2.XYZ][2.XYZ][2.XYZ][2.XYZ]][1.XYZ[2.XYZ][2.XYZ][2.XYZ][2.XYZ][2.XYZ][2.XYZ][2.XYZ]][1.XYZ][1.XYZ[2.XYZ][2.XYZ][2.XYZ][2.XYZ][2.XYZ]]]
\end{forest}


\kant[2]    
\end{document}

Original answer

This code hard-codes all edges and ignores some node option variations. However, it replaces edges from nodes, as well as edges to them. At least, it currently replaces some and it hopefully will soon replace others.

output

Complete code:

\documentclass[a4paper,12pt]{article}
\usepackage{geometry,blindtext}% geometry or similar is needed for correct A4 layout
\usepackage[edges]{forest}
% addaswyd o gôd Sašo Živanović: http://tex.stackexchange.com/a/296771/
\def\hiddenparcommand{\par}
\newcommand\otherhiddenparcommand{\par\noindent}
\newcommand\hiddencommacommand{, }
\forestset{%
  declare keylist register={split here ids},% the list of nodes to split the tree at
  split here ids={},
  declare keylist register={split here interjects},% the list of comments to put in between the tree parts
  split here interjects={},
  declare toks register=split here toks,
  declare dimen register=tmpdima,
  tmpdima'=0pt,
  declare dimen register=tmpdimb,
  tmpdimb'=0pt,
  declare dimen register=tmpdimc,
  tmpdimc'=0pt,
  declare count={split parent id}{0},
  declare count={split descendant id}{0},
  declare toks={split descendant}{},
  declare long step={current and preceding parents}{}{filter={current and preceding nodes}{>OO={n children}{n children}}},
  declare keylist={splitter list}{},
  to widest/.style={
    tikz+={\path (\forestregister{tempdima}, \forestoption{y}) -- (\forestregister{tempdimb}, \forestoption{y});},
  },
  hide commas/.style={%
    split here toks+={\hiddencommacommand},
    split here toks+={#1},
  },
  split dir tree pre/.style={%
    label={[text=gray, anchor=north, font=\scriptsize]below:{[cont.]}{}},
    tempcountd/.option=id,
    temptoksc/.option=name,
    for Nodewalk={on invalid=fake}{do until={ > O_ O_ =!=|  {split descendant id}{0} {level}{0}  }{split descendant id/.register=tempcountd, split descendant/.register=temptoksc, previous node}}{},
  },
  split dir tree post/.style={%
    label={[font=\scriptsize, anchor=south, text=gray]above:{[cont.]}{}},
    tikz+/.process={% this draws an edge to the first node after a break
      OOOw+nw3  {edge}{edge label}{id}{##1+1}%
      {%
        \path [##1] (!u.parent anchor |- .north) ++(\forestregister{folder indent},1ex) coordinate (before ##3) |- (.child anchor)##2 ;
      }%
    },
  },
  split dir tree/.code={%
    \forestset{%
      for tree={
        folder,
        grow'=0,
        edge path={},
      },
      tikz+/.process={Ow{id}{\path (.parent anchor) coordinate (before ##1);}},
      draw tree stage/.style={
        for root'={
          tempdima/.min={%
            >OOw2+d{x}{min x}{####1+####2}%
          }{tree},
          tempdimb/.max={%
            >OOw2+d{x}{max x}{####1+####2}%
          }{tree},
          for tree={%
            to widest,
          },
        },
        tempcountb'=-1,
        do until={%
          strequal((split_here_ids),"")
        }{%
          tempkeylistb'={},
          tempkeylista'={},
          split register={split here ids}{,}{tempcounta,tempkeylistb+},
          split register={split here interjects}{,}{temptoksa,tempkeylista+},
          split here ids'/.register=tempkeylistb,
          split here interjects'/.register=tempkeylista,
        % Sašo Živanović: http://chat.stackexchange.com/transcript/message/28484520#28484520
         for nodewalk={%
           draw tree processing order/.style={%
             filter={tree}{> ORw+n< OR> & {id}{tempcounta}{########1+1}{id}{tempcountb}}%
           }%
         }{},
          for root'={draw tree},
          TeX/.process={Rw{temptoksa}{\otherhiddenparcommand ####1\hiddenparcommand}},
          tempcountb'/.register=tempcounta,
        },
        for nodewalk={%
          draw tree processing order/.style={%
            filter={tree}{>OR>{id}{tempcountb}}%west
          }%
        }{},
        for root'={draw tree},
      },
    }%
  },
  split dir here auto/.style={%
    split dir tree pre,
    !next node.split dir tree post,
    split here ids+/.option=id,
    split={#1}{,}{split here toks,hide commas},
    split here interjects/.register=split here toks,
  },
  split dir tree auto/.style={%
    split dir tree,
    before drawing tree={%
      tempdima/.max={y}{tree},
      tempdimc/.register=tempdima,
      tempdimd/.min={y}{tree},
      tempdima-/.register=tempdimd, % cyfanswm yr y sy'n angen
      tempdimb'=\textheight,
      tmpdima'=10ex,
      tmpdimc'=\pagetotal,
      tempcounta/.option=id,
      temptoksb/.option=name,
      while={%
        >RR>{tempdima}{tempdimb}%
      }{%
        for nodewalk={%
          id/.register=tempcounta,
          temptoksb/.option=name,
          until={%
            > ROw2+d RRw2+d > {tempdimc}{y}{##1-##2} {tmpdima}{tmpdimc}{\textheight-##2-##1}%
          }{next node, split parent id/.register=tempcounta, split parent id+'=1},
          previous node,
          split dir here auto=continued,%tmpdima,
          next node,
          split parent id/.option=id,
          split parent id+'=1,
          tempcounta/.option=id,
          tempcountb/.option=split parent id,
          tempdima/.option=y,
          tempdimc/.register=tempdima,
          tempdima-/.register=tempdimd,
          tmpdima'=15ex,
          tmpdimc'=0pt,
        }{},
      },
      where level=0{}{
        if split parent id=0{split parent id/.register=tempcountb}{},
        if={ > OOw+n< {!u.id}{split parent id}{##1-1} }{
          tikz+/.process={ OOOw3 {edge}{edge label}{split parent id} {\path [##1] (!u.parent anchor |- before ##3) ++(\forestregister{folder indent},0pt) |- (.child anchor)##2;}}
        }{
          if={ > OOw+n= {id}{split parent id}{##1-1} }{}{
            tikz+/.process={ OOw2 {edge}{edge label} {\path [##1] (!u.parent anchor) ++(\forestregister{folder indent},0pt) |- (.child anchor)##2;}}
          },
        },
      },
      where n children=0{}{ 
        if={ > OO> {!l.id}{split descendant id} }{
          tikz+/.process={ OOw2 {edge}{split descendant} { \path [##1] (.parent anchor) ++(\forestregister{folder indent},0pt) coordinate (a) -- (a |- ##2.parent anchor) -- ++(0pt,-1ex);  }
          },
        }{},
      },
      temptoksa/.option=!r.name,
      split register={split here ids}{,}{splitter split},
    },
  },
  splitter split/.style={
    for nodewalk={id=#1}{
      tempcounta/.option=id,
      tempcountc/.option=split parent id,
      tempkeylista'=,
      for filter={current and preceding nodes}{>O_>{n children}{0}}{
        if={> OR > OR < & {!l.id}{tempcounta} {id}{tempcountc}  }{
          tempkeylista+/.option=name,
        }{},
      },
      splitter list/.register=tempkeylista,
      tikz+/.process={ 
        OOw2{split parent id}{edge}{
          \edef\tempa{\foresteoption{splitter list}}
          \foreach \i in \tempa {\path [##2] (\i.parent anchor |- before ##1) ++(\forestregister{folder indent},0pt)  coordinate (b) -- (.parent anchor -| b) -- ++(0,-1ex); }
        }
      },
    },
    if nodewalk valid={next}{temptoksa/.option=!next.name}{temptoksa'={}},
  },
}
\begin{document}
\blindtext
\twocolumn

\begin{forest}
  split dir tree auto,
  [XYZ[XYZ[XYZ[XYZ[XYZ]]][XYZ[XYZ[XYZ]]][XYZ[XYZ[XYZ][XYZ][XYZ][XYZ][XYZ][XYZ][XYZ]][XYZ[XYZ][XYZ][XYZ][XYZ][XYZ]][XYZ[XYZ]][XYZ[XYZ][XYZ]]][XYZ[XYZ[XYZ][XYZ]]][XYZ[XYZ[XYZ][XYZ][XYZ][XYZ][XYZ][XYZ]][XYZ[XYZ]][XYZ[XYZ][XYZ][XYZ]]][XYZ[XYZ[XYZ]]][XYZ[XYZ[XYZ][XYZ][XYZ]]][XYZ[XYZ[XYZ][XYZ][XYZ][XYZ][XYZ][XYZ]]][XYZ[XYZ[XYZ][XYZ][XYZ][XYZ][XYZ][XYZ][XYZ][XYZ][XYZ][XYZ][XYZ][XYZ][XYZ][XYZ][XYZ][XYZ][XYZ][XYZ][XYZ]][XYZ[XYZ][XYZ]][XYZ[XYZ][XYZ][XYZ]]][XYZ[XYZ[XYZ][XYZ][XYZ][XYZ][XYZ][XYZ][XYZ]][XYZ[XYZ]][XYZ[XYZ]]][XYZ[XYZ[XYZ][XYZ][XYZ][XYZ][XYZ][XYZ][XYZ]][XYZ[XYZ]]][XYZ[XYZ[XYZ][XYZ]]][XYZ[XYZ[XYZ][XYZ][XYZ][XYZ][XYZ][XYZ][XYZ][XYZ][XYZ][XYZ][XYZ][XYZ][XYZ][XYZ][XYZ][XYZ]][XYZ[XYZ]]][XYZ[XYZ[XYZ][XYZ][XYZ][XYZ][XYZ][XYZ][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