3

Consider the following MWE:

\usemodule[tikz]
\starttext
\starttikzpicture
    \node[draw,font=\big,text width=4.75cm,align=flush left] {This text should not hyphenate.};
\stoptikzpicture
\stoptext

As included within the node's text I do not expect the text to hyphenate. But that is what I get (with ConTeXt from TL2018 and current beta):

hyphenation

Just for comparison: A similar LaTeX document will not reproduce that strange behavior (i.e. the flush left option actually does what it says).

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
    \node[draw,text width=4.75cm,font=\large,align=flush left] {This text should not hyphenate.};
\end{tikzpicture}
\end{document}

As I had some issues with ConTeXt and text alignment in the past, my question is: Is this kind of behavior to be expected? And how to actually flush left align a node in TikZ in ConTeXt?

  • In ConteXt, leftflushed does not automatically imply nothypehnated. I don't know how tikz maps node options to low level directives – Aditya Jan 22 at 20:24
  • @Aditya Thanks, then this is a bug in TikZ because the manual states that flush left will suppress hyphenation. Actually, that also answers my question, so feel free to write up an answer :) – TeXnician Jan 22 at 20:31
4

The problem is font=\big. The macro \big is a math command to choose a different delimiter size, not a font command. Unfortunately, when using \big in ConTeXt without a delimiter, it will just silently swallow the following token. However, if you try the following example in Plain TeX, it will get noisy.

\input tikz
\tikz \node[draw,font=\big,text width=4.75cm,align=flush left] {This text should not hyphenate.};
\bye
! Missing delimiter (. inserted).
<to be read again> 
\rightskip 
\pgfutil@raggedright ->\rightskip 
                                  \z@ plus2em \spaceskip .3333em \xspaceskip...

So to rectify this problem, just remove font=\big or replace it with \tfa or \switchtobodyfont[big] or something similar.

\usemodule[tikz]
\starttext
\tikz \node[draw,text width=4.75cm,align=flush left] {This text should not hyphenate.};
\stoptext

enter image description here

But what is this? It looks a bit more ragged but why is it still hypenated? This is because the flush left and flush right option use these macros from pgfutil-common.tex:

% Ragged left and ragged right

\def\pgfutil@raggedright{\rightskip\z@ plus2em \spaceskip.3333em \xspaceskip.5em\relax}
\def\pgfutil@raggedleft{\leftskip\z@ plus2em \rightskip\z@ \spaceskip.3333em \xspaceskip.5em\parfillskip0pt\relax}

These are the definitions of \raggedright and \raggedleft from Plain TeX. These are by far not as ragged as the LaTeX version, where the margin skip is set to 0pt plus 1fil. So to emulate the LaTeX raggedness, you have to redefine \pgfutil@raggedright.

\usemodule[tikz]
\unprotect
\def\pgfutil@raggedright
  {\rightskip=0pt plus 1fil
   \leftskip=0pt
   \parindent=0pt
   \relax}
\protect
\starttext
\tikz \node[draw,text width=4.75cm,align=flush left] {This text should not hyphenate.};
\stoptext

enter image description here


N.B.: ConTeXt's \raggedright is also not very ragged. It sets stretch of \rightskip only to twice the body font size, i.e. \rightskip=0pt plus 24pt in this case.

  • Thanks for this great answer. Obviously one should not believe the TikZ manual when it comes to ConTeXt… – TeXnician Jan 23 at 8:16
  • @TeXnician Can you elaborate? I checked the manual for font=\big but could not find anything. – Henri Menke Jan 23 at 8:21
  • No, I mean for align=flush left where it explicitly says that hyphenation will be suppressed. – TeXnician Jan 23 at 8:56
3

Henri has beautifully debugged the problem, but let me propose an alternative solution. When using TikZ in ConTeXt, I always use ConTeXt macros to handle text formatting:

\usemodule[tikz]
\starttext
\starttikzpicture
    \node[draw,font=\big,text width=4.75cm,align=flush left] {This text should not hyphenate.};

    \node at (0, -2cm) 
        {\framed[ width=4.75cm, align={flushleft}]
            {This text does not hyphenate}};

    \node at (0, -4cm) 
        {\framed[ width=4.75cm, align={flushleft,nothyphenated}]
            {This text does not hyphenate}};

    % The result that you wanted:
    \node at (0, -6cm) 
        {\framed[foregroundstyle={\switchtobodyfont[big]}, width=4.75cm, align={flushleft,nothyphenated}]
            {This text does not hyphenate}};

\stoptikzpicture
\stoptext

which gives

enter image description here

You can add the right value to offset key of \framed to get the same offset as TikZ.

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.