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?

  • you have problems with Spanish babel, which apparently redefine some character(s). unfortunately tikz library label is not able to fix this. – Zarko Aug 25 '17 at 02:36
  • 2
    for solution see https://tex.stackexchange.com/questions/19393/problem-with-spanish-babel-package, answer of Gonzalo Medina,i.e. use \usepackage[spanish,es-noquoting]{babel} instead of \usepackage[spanish]{babel}. – Zarko Aug 25 '17 at 02:52
  • But i need quotations to be understand by latex..@Zarko, spanish needs those symbols –  Aug 25 '17 at 02: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 Aug 25 '17 at 03:00
  • Your code doesn't produce the error reported. Compilation fails with `! Undefined control sequence. \undefinedpagestyle

    l.28 \pagestyle{mystyle}

    ? `

    – cfr Aug 25 '17 at 21:49
  • If \pagestyle{mystyle} is not relevant to your question, please remove it from your code here. Always ensure that the exact code you post produces the output shown by testing compilation in a new, clean .tex document. – cfr Aug 25 '17 at 22:44

1 Answers1

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>

cfr
  • 198,882
  • Comments are not for extended discussion; this conversation has been moved to chat. – Joseph Wright Sep 01 '17 at 20:03
  • with your answer but changing \usepackage[spanish]{babel}it compiled without error in latex 2017 –  Oct 04 '17 at 05:00
  • When I tried in my whole thesis, it produces lot of errors related to chemmacros –  Oct 04 '17 at 05: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 Oct 04 '17 at 12:58
  • @cfr do you think that would be helpful? The document compiles and is OK using es-noquoting option. Although I now it is not the best way. –  Oct 04 '17 at 13:01
  • @HernanMiraola Yes. As you say, it is not the best way. But, obviously, it is your call as you're the one who would have to make the minimal example. – cfr Oct 04 '17 at 13:03
  • @JosephWright Unfortunately, that room is frozen and the system's algorithm for offering to create a new one is not offering to create another. – cfr Oct 04 '17 at 13:04
  • 1
    Right, I will do it but later. A minimal nonworking example to show that interference with chemmacros. –  Oct 04 '17 at 13:07
  • @cfr Hi, Is there a ç into your code? – Sebastiano May 05 '18 at 10:57
  • @Sebastiano The code posted produces the output posted. There is no literal ç. Is that not what you'd expect the shorthand to produce in Spanish? – cfr May 22 '18 at 01:08
  • @cfr Yes of course. I have thought that is was an error. Upvote you. – Sebastiano May 22 '18 at 17:24
  • @Sebastiano It is just to show the shorthands work outside forest environments as expected. I know it looks weird in the output, but it is just for illustrative purposes is all. – cfr May 23 '18 at 01:48