2

My questions concerns the following MWE:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{datavisualization}
\usetikzlibrary{datavisualization.formats.functions}
\begin{document}
\tikz[scale=4]
    \datavisualization[
        school book axes,
        visualize as smooth line=myfunction,
        myfunction={pin in data={text=$f(x)$}}]
    data [set=myfunction, format=function] {
        var x : interval [0:1];
        func y = \value x^2;
    };
\end{document}

which makes the following pretty graph: Graph of y = x^2, with label

The problem is that when I try to change my label text from $f(x)$ to $f[x]$ I receive the error Missing $ inserted. on the line containing };.

I figure it probably has to do with TikZ parsing the brackets before math-mode gets to them, but I don't know how to fix it. I tried replacing [ and ] with \[ and \] but this didn't help at all. I also realized that I could replace $f[x]$ with $f$[$x$], but this seems like the wrong way to go.

How can I include brackets in my label?

1 Answer 1

3

(La)TeX can not balance square brackets and it gets confused thinking that the ] in f[x] is closing the opening [ from \datavisualization; help it by using an extra pair of braces,as in {$f[x]$} so the inner brackets are hidden:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{datavisualization}
\usetikzlibrary{datavisualization.formats.functions}
\begin{document}
\tikz[scale=4]
    \datavisualization[
        school book axes,
        visualize as smooth line=myfunction,
        myfunction={pin in data={text={$f[x]$}}}]
    data [set=myfunction, format=function] {
        var x : interval [0:1];
        func y = \value x^2;
    };
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .