2

I have a problem when making a flow chart with forest. Here is the MWE and below i past what the log file says:

\documentclass[12pt,twoside]{report}
  \usepackage[spanish]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc} 
\usepackage{tikz}
\usepackage{forest}
\usetikzlibrary{babel} 
\begin{document}

\chapter*{Resume} % * avoids numeration

\begin{forest}
  for tree={
    rounded corners, draw, align=center, top color=white, bottom color=blue!20,
    edge+=->,
    l sep'+=10pt,
  },
  [Solvatación
    [Explícito+Implícito
      [Solvateshell + Cosmo]
      [Packmol + Cosmo]
    ]
    [Implícito
      [Cosmo]
    ]
  ]
\end{forest}
\end{document}

The error is:

! Argument of \language@active@arg> has an extra }. <inserted text> \par l.16 \end{forest} I've run across a }' that doesn't seem to match anything. For example, \def\a#1{...}' and \a}' would produce this error. If you simply proceed now, the \par' that I've just inserted will cause me to report a runaway argument that might be the root of the problem. But if your }' was spurious, just type 2' and it will go away. Runaway argument?

Any help?

6
  • you have problems with Spanish babel, which apparently redefine some character(s). unfortunately tikz library label is not able to fix this.
    – Zarko
    Commented Aug 25, 2017 at 2:36
  • 2
    for solution see tex.stackexchange.com/questions/19393/…, answer of Gonzalo Medina,i.e. use \usepackage[spanish,es-noquoting]{babel} instead of \usepackage[spanish]{babel}.
    – Zarko
    Commented Aug 25, 2017 at 2:52
  • But i need quotations to be understand by latex..@Zarko, spanish needs those symbols
    – user134500
    Commented Aug 25, 2017 at 2:55
  • than you need to wait to some spanish babel guru for help ... in given link is also answer of Stefan Kottwitz, which can solve your problem without interfering to quotes
    – Zarko
    Commented Aug 25, 2017 at 3:00
  • Your code doesn't produce the error reported. Compilation fails with ! Undefined control sequence. <argument> \undefinedpagestyle l.28 \pagestyle{mystyle} ?
    – cfr
    Commented Aug 25, 2017 at 21:49

1 Answer 1

6

You can work around this, without turning Babel short-hands off globally, by patching an internal configuration macro. Note: this patches an internal macro. I strongly recommend emailing Forest's author with a link to this question as Sašo may have a safer alternative (or be willing to create one). Ideally, this should be part of Forest itself, I think.

Caveat emptor

The problem is that Forest does not invoke tikzpicture until the draw tree stage. By this point, the tree preamble and tree specification has been parsed. So although TikZ switches off the short-hands when the babel library is used, this comes too late for Forest. The trouble is already made.

What we need to do is turn off the short-hands earlier - as early as possible, in fact - in the process. Ideally, we want to do this before stages are defined, which happens even before the tree's preamble is parsed. There is a way to alter what Forest does here by using the optional parenthesised argument, but currently the only available key recognised here is stages and, in any case, anything we pass through in this argument will be executed only after Forest has defined its default stages. This might or might not cause problems now, but it would certainly be safer to turn short-hands off before this is done.

For this reason, I tried patching the macro \forest@config by prepending a copy of the code from tikz.code.tex responsible for switching off short-hands. This ensures that short-hands are off even before Forest defines the default value of stages and well before any local configuration is done, let alone the tree preamble and specification.

To do this, I loaded etoolbox and added

\makeatletter
\pretocmd\forest@config{% from tikz.code.tex
  \iftikz@handle@active@code\tikz@switchoff@shorthands\fi}{\typeout{Patched \string\forest@config\ OK.}}{\typeout{Failed to patch \string\forest@config\ - oh, dear.}}
\makeatother

to the preamble.

This patch affects only tree creation. If you are setting forest keys outside a forest environment or similar, using \forestset, then you must do one of three things:

  1. avoid any problematic characters here;
  2. define your settings before short-hands are activated by Babel i.e. in your document preamble (OK to do this after loading Babel, I think, so long as it is before \begin{document};
  3. switch short-hands off before using \forestset and on afterwards.

I prefer to keep global settings in the preamble anyway, so I suggest using the second option, which is certainly the most straightforward.

Complete code:

\documentclass[12pt,twoside,a4paper,spanish]{report}
\usepackage[headheight=18pt, width=150mm, top=25mm, bottom=25mm, bindingoffset=6mm, headsep=18pt]{geometry}
\usepackage{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[activate={true,nocompatibility},final,tracking=true,kerning=true,spacing=true,factor=1100,stretch=10,shrink=10]{microtype}
\usepackage[hyphens]{url}
\usepackage{textcomp}
\usepackage{tikz}
\usepackage{forest,etoolbox}
\usetikzlibrary{babel}
\makeatletter
\pretocmd\forest@config{% from tikz.code.tex
  \iftikz@handle@active@code\tikz@switchoff@shorthands\fi}{\typeout{Patched \string\forest@config\ OK.}}{\typeout{Failed to patch \string\forest@config\ - oh, dear.}}
\makeatother

\begin{document}

\chapter*{Resume} % * avoids numeration

"c
\begin{forest}
  for tree={
    rounded corners, draw, align=center, top color=white, bottom color=blue!20,
    edge+=->,
    l sep'+=10pt,
  },
  [Solvatación
    [Explícito+Implícito
      [Solvateshell + Cosmo]
      [Packmol + Cosmo]
    ]
    [Implícito
      [Cosmo]
    ]
  ]
\end{forest}
"c

\end{document}

The "c are to show active short-hands work outside forest, both before and after.

switching active short-hands off in <code>forest</code>

12
  • Comments are not for extended discussion; this conversation has been moved to chat.
    – Joseph Wright
    Commented Sep 1, 2017 at 20:03
  • with your answer but changing \usepackage[spanish]{babel} it compiled without error in latex 2017
    – user134500
    Commented Oct 4, 2017 at 5:00
  • When I tried in my whole thesis, it produces lot of errors related to chemmacros
    – user134500
    Commented Oct 4, 2017 at 5:05
  • @HernanMiraola Hard to say without a minimal example. Ask a new question with an example which demonstrates the problem. Loading the babel library affects all tikzpictures, but shouldn't do so in problematic ways. However, remember that it means shorthands are off inside these environments, so you cannot use them in text in the usual ways. The code I added for Forest shouldn't affect anything other than forest trees, though.
    – cfr
    Commented Oct 4, 2017 at 12:58
  • 1
    Right, I will do it but later. A minimal nonworking example to show that interference with chemmacros.
    – user134500
    Commented Oct 4, 2017 at 13:07

You must log in to answer this question.