Ich habe in eurem Froum schon ein wenig gesucht... Aber kein passendes Beispiel gefunden. Ich hoffe ihr helft mir auch ohne Minimalbeispiel. Ich will je nach boolean Deklaration (true or false) eine gewisse Code Zeile in meinem Latex Programm durchlaufen lassen oder nicht. Danke.

Öffne in Overleaf
\documentclass{article}
\usepackage{xstring}

\newcommand{\DEBUG}{OFF}%

\begin{document}
    \IfStrEq{\DEBUG}{ON}{
        DEBUG was on
    }{
    DEBUG was off
}
\end{document}

geht aber nicht in Verbindung mit https://texwelt.de/wissen/fragen/23135/pagebreak-mit-einschrankungen mit der Ausblendung von der Programmzeile split dir tree auto, -> funktioniert nicht im gegensatz zum Minimal Bsp. UPDATE 1:

Öffne in Overleaf
    \begin{forest}
        for tree={
            folder,
            grow'=0,
            fit=band,
        },
            \IfStrEq{\DEBUG}{ON}{
                split dir tree auto,
            }{
            %Text
         }
        %split dir tree auto, ->Auskommetiert damit es funktioniert
        [ XYZ
        [ XYZ
        [ XYZ,edge label={node[pos=0.75,above,font=\scriptsize]{1}}
         [ XYZ,edge label={node[pos=0.75,above,font=\scriptsize]{1}}
        ]
        ]
        ]
        ]
    \end{forest}

Update 2: Die If Bedingung funktioniert in diesem Zusammenhang nicht. -> documentclass[11pt,a4paper,titlepage,bibliography=totoc,numbers=noenddot,abstract=on,multi,dvipsnames,svgnames,x11names]{scrreprt}

Öffne in Overleaf
\usepackage{storebox}
\usepackage[edges]{forest}
\usepackage{adjustbox}
\usepackage{ifthen}
\newboolean{somevariable}
\setboolean{somevariable}{false}

%Zeilenumbruch in der tikz Umgebung!
% 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 keylist={split here auto siblings}{},% a list to hold the siblings which need edge restoration
    declare toks register=split here toks,
    declare dimen register=tmpdima,
    tmpdima'=0pt,
    declare dimen register=tmpdimb,
    tmpdimb'=0pt,
    declare dimen register=tmpdimc,
    tmpdimc'=0pt,
    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.]}{}},
    },
    split dir tree post/.style={%
        label={[font=\scriptsize, anchor=south, text=gray]above:{[cont.]}{}},
    },
    split dir tree auto post/.style={% this gets applied to the first node after a break
        split dir tree post,
        tempkeylistc'={},
        tmpdimb/.option=y,
        for nodewalk={
            while={
                > ORw2+d _+d < On=! & {y}{tmpdimb}{##2-##1} {\textheight-#1} {n'}{1}%
            }{
            next,
            tempkeylistc/.option=name
        }%
    }{},
    % save the list
    split here auto siblings/.register=tempkeylistc,
    tikz+/.process={% this tries to redraw the edges to the following siblings
        OOw2{edge}{id}%
        {%
            \path [##1] (!u.parent anchor |- .north) ++(\forestregister{folder indent},1ex) coordinate (before ##2) |- (.child anchor);
            \edef\tempa{\foresteoption{split here auto siblings}}
            \foreach \i in \tempa \path [##1] (before ##2) |- ({forest cs:\i.child anchor});
        }%
    },
},
split dir tree/.code={%
    \forestset{%
        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}}%
            }%
        }{},
        for root'={draw tree},
    },
}%
},
split dir here auto/.style n args=2{%
    split dir tree pre,
    !next node.split dir tree auto post=#2,
    split here ids+/.option=id,
    %     !next node.split resume 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,
        tempdimb'=\textheight,
        tmpdima'=10ex,
        tmpdimc'=\pagetotal,
        while={%
            >RR>{tempdima}{tempdimb}%
        }{%
        for nodewalk={%
            root',
            until={%
                > ROw2+d RRw2+d > {tempdimc}{y}{##1-##2} {tmpdima}{tmpdimc}{\textheight-##2-##1}%
            }{next node},
            previous node,
            split dir here auto/.process={R_w2{tmpdima}{continued}{{##2}{##1}}},
            next node,
            tempdima/.option=y,
            tempdimc/.register=tempdima,
            tempdima-/.register=tempdimd,
            tmpdima'=15ex,
            tmpdimc'=0pt
        }{},
    },
},
},
}
%Zeilenumbruch in der tikz Umgebung! Ende

\begin{document}

    \begin{forest}
        for tree={
            folder,
            grow'=0,
            fit=band,
        },  
        \ifthenelse{\boolean{somevariable}}{split dir tree auto,}{} %IF ABFRAGE FUNKTIONIERT NICHT 
        [ XYZ
        [ XYZ
        [ XYZ,edge label={node[pos=0.75,above,font=\scriptsize]{1}}
        [ XYZ,edge label={node[pos=0.75,above,font=\scriptsize]{1}}
        ]
        ]
        ]
        ]
    \end{forest}

\end{document}

gefragt 28 Sep '18, 11:50

helmutW's gravatar image

helmutW
116712
Akzeptiert-Rate: 40%

bearbeitet 30 Sep '18, 09:39

cgnieder's gravatar image

cgnieder
22.1k243463

1

Was heißt denn hier »ohne Minimalbeispiel«? Das Beispiel in deiner Frage ist quasi das Muster eines Minimalbeispiels! (+1)

(28 Sep '18, 13:46) Henri
(28 Sep '18, 13:54) helmutW

Es gibt einige Methoden, Booleans mit TeX zu basteln, um Dinge auszublenden. xstring ist da meiner Meinung nach noch vergleichsweise wenig gut geeignet. Allerdings habe ich keine Methode gefunden, die in Deinem forest-Fall funktioniert. Da sind, vermute ich mal, sehr komplexe Dinge am Laufen, die sich unter Umständen mit den If-Konstrukten beißen. split dir tree auto ist ja kein normaler Text sondern eher ein Keyword, ich weiß nicht genau, wie das eingelesen oder behandelt wird, aber das könnte ein Hindernis sein.

(28 Sep '18, 15:35) moewe

Sehe gerade, dass Du bei TeX.SX schon gute Antworten bekommen hast: https://tex.stackexchange.com/q/452900/35864. Ich hätte Dir in etwa auch das gesagt, was Skillmon geschrieben hat. Von ifthen bin ich nicht so ein Freund (ein Grund: https://tex.stackexchange.com/q/449723/35864). Dann bleibt TeX's \if..., etoolbox oder LaTeX3. Meine Präferenz geht dabei meist zu etoolbox. Aber wenn man eh schon LaTeX3 nutzt oder damit herumspielen möchte, dann ist das auch eine sehr gute Idee (mit einigen netten Details wie lazy evaluation - wenn's möglich ist).

(28 Sep '18, 15:39) moewe

@moewe habe ich schon gesehen... Habe es direkt ausprobiert. Geht bei mir nicht. Ich meine in diesem speziellen Fall. Siehe Update 2

(28 Sep '18, 15:45) helmutW

Anbei die Lösung:

the problem is that the ifthen booleans are not expandable (expandability is a strange concept in TeX and there are different levels of expandability, take a look at What is expansion for example). You need to use a boolean style that is expandable in that context. For example the following doesn't throw an error and is using the toggles provided by etoolbox:

Öffne in Overleaf
\documentclass[11pt,a4paper,titlepage,bibliography=totoc,numbers=noenddot,abstract=on,multi,dvipsnames,svgnames,x11names]{scrreprt}

\usepackage{storebox}
\usepackage[edges]{forest}
\usepackage{adjustbox}

\usepackage{etoolbox}
\newtoggle{somevariable}
\togglefalse{somevariable}

%Zeilenumbruch in der tikz Umgebung!
% 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 keylist={split here auto siblings}{},% a list to hold the siblings which need edge restoration
    declare toks register=split here toks,
    declare dimen register=tmpdima,
    tmpdima'=0pt,
    declare dimen register=tmpdimb,
    tmpdimb'=0pt,
    declare dimen register=tmpdimc,
    tmpdimc'=0pt,
    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.]}{}},
    },
    split dir tree post/.style={%
        label={[font=\scriptsize, anchor=south, text=gray]above:{[cont.]}{}},
    },
    split dir tree auto post/.style={% this gets applied to the first node after a break
        split dir tree post,
        tempkeylistc'={},
        tmpdimb/.option=y,
        for nodewalk={
            while={
                > ORw2+d _+d < On=! & {y}{tmpdimb}{##2-##1} {\textheight-#1} {n'}{1}%
            }{
            next,
            tempkeylistc/.option=name
        }%
    }{},
    % save the list
    split here auto siblings/.register=tempkeylistc,
    tikz+/.process={% this tries to redraw the edges to the following siblings
        OOw2{edge}{id}%
        {%
            \path [##1] (!u.parent anchor |- .north) ++(\forestregister{folder indent},1ex) coordinate (before ##2) |- (.child anchor);
            \edef\tempa{\foresteoption{split here auto siblings}}
            \foreach \i in \tempa \path [##1] (before ##2) |- ({forest cs:\i.child anchor});
        }%
    },
},
split dir tree/.code={%
    \forestset{%
        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}}%
            }%
        }{},
        for root'={draw tree},
    },
}%
},
split dir here auto/.style n args=2{%
    split dir tree pre,
    !next node.split dir tree auto post=#2,
    split here ids+/.option=id,
    %     !next node.split resume 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,
        tempdimb'=\textheight,
        tmpdima'=10ex,
        tmpdimc'=\pagetotal,
        while={%
            >RR>{tempdima}{tempdimb}%
        }{%
        for nodewalk={%
            root',
            until={%
                > ROw2+d RRw2+d > {tempdimc}{y}{##1-##2} {tmpdima}{tmpdimc}{\textheight-##2-##1}%
            }{next node},
            previous node,
            split dir here auto/.process={R_w2{tmpdima}{continued}{{##2}{##1}}},
            next node,
            tempdima/.option=y,
            tempdimc/.register=tempdima,
            tempdima-/.register=tempdimd,
            tmpdima'=15ex,
            tmpdimc'=0pt
        }{},
    },
},
},
}
%Zeilenumbruch in der tikz Umgebung! Ende

\begin{document}

    \begin{forest}
        for tree={
            folder,
            grow'=0,
            fit=band,
        },  
        \iftoggle{somevariable}{split dir tree auto,}{} %IF ABFRAGE FUNKTIONIERT NICHT 
        [ XYZ
        [ XYZ
        [ XYZ,edge label={node[pos=0.75,above,font=\scriptsize]{1}}
        [ XYZ,edge label={node[pos=0.75,above,font=\scriptsize]{1}}
        ]
        ]
        ]
        ]
    \end{forest}

\end{document}
Permanenter link

beantwortet 28 Sep '18, 17:05

helmutW's gravatar image

helmutW
116712
Akzeptiert-Rate: 40%

6

Meine Antwort von TeX.SX einfach so zu kopieren, während unter dieser ein Kommentar ist, dass ich gedenke hier ebenfalls eine Antwort zu formulieren, und dann auch noch ohne meine Antwort direkt in der Kopie zu referenzieren, halte ich für fragwürdig. Von der Verwendung von ifthen würde ich bis auf wenige Ausnahmen abraten (persönlich würde ich es nicht verwenden, da es häufig eher Probleme schafft, als es diese löst -- vor allem wenn man expl3 kennt).

(28 Sep '18, 18:16) Skillmon

@skillmon war nicht mit absicht. sorry. danke.

(03 Okt '18, 09:31) helmutW
Deine Antwort
Vorschau umschalten

Folgen dieser Frage

Per E-Mail:

Wenn sie sich anmelden, kommen Sie für alle Updates hier in Frage

Per RSS:

Antworten

Antworten und Kommentare

Markdown-Grundlagen

  • *kursiv* oder _kursiv_
  • **Fett** oder __Fett__
  • Link:[Text](http://url.com/ "Titel")
  • Bild?![alt Text](/path/img.jpg "Titel")
  • nummerierte Liste: 1. Foo 2. Bar
  • zum Hinzufügen ein Zeilenumbruchs fügen Sie einfach zwei Leerzeichen an die Stelle an der die neue Linie sein soll.
  • grundlegende HTML-Tags werden ebenfalls unterstützt

Frage-Themen:

×21
×9
×2

gestellte Frage: 28 Sep '18, 11:50

Frage wurde gesehen: 5,864 Mal

zuletzt geändert: 03 Okt '18, 09:31