# TikZ does not draw functions anymore

TeX - LaTeX Asked by PUserR on September 30, 2020

I am using the latest TeXstudio version with PdfLaTeX as my compiler. I have this commands enabled: pdflatex.exe -synctex=1 -shell-escape -interaction=nonstopmode %.tex. The document is getting created but TikZ does not draw the functions. The Code works in Overleaf (online editor) perfectly fine with the drawn functions so there must be a problem with my PdfLaTeX or my TeXstudio. I tried reinstalling MikTeX and TeXstudio. I have even installed on a virtual machine to look if it works there but without success. It also does not work in WinShell. I also tried to compile the document with LuaLaTeX but again, without success. Furthermore, Overleaf’s default compiler was set to PdfLaTeX. I thinks that there is something wrong with my PdfLaTeX but I have no idea left for a possibility to solve that problem. My Code is:

documentclass{article}

usepackage{pgfplots}
usetikzlibrary{through,calc,arrows,snakes}

pgfplotsset{compat=1.16}

begin{document}
begin{center}
begin{tikzpicture}[scale=0.8, x=2cm, y=2cm, axis/.style={ ->, >=stealth'}]
draw[dotted,color=black, xstep=1cm, ystep=1cm] (-1.9,0) grid (1.9,3.9);
draw[axis] (-2,0) -- (2,0) node[above] {small $x$};
draw[axis] (0,0) -- (0,4) node[right] {small $y$};
foreach x/xtext in {-2/-2, -1/-1, 0/0, 1/1} draw[shift={(x,0)}] (0pt,2pt) -- (0pt,-2pt) node[below, fill=white] {small xtext};
foreach y/ytext in {1/1, 2/2, 3/3}  draw[shift={(0,y)}] (2pt,0pt) -- (-2pt,0pt) node[left, fill=white] {small ytext};
% functions
draw[color=red, thick] plot[domain=-2:2, samples=250] function{x*x} node[right] {small $f(x)$};
end{tikzpicture}
end{center}
end{document}


These are the results:

As you can see on the left it looks perfectly fine (Overleaf) but on the right (TeXstudio) it doesnt. I want to continue writing in TeXstudio not in Overleaf so it would be great if this is working.

Your code is calling gnuplot. It need both gnuplot installed and -shell-escape (or enable-write18) compilation option.

Answered by gigiair on September 30, 2020

This works in local (recent) MikTeX installation as well in Overleaf:

documentclass{article}
usepackage{pgfplots}
pgfplotsset{compat=1.16}
usetikzlibrary{arrows,
calc,
decorations.pathmorphing,
through}

begin{document}
begin{center}
begin{tikzpicture}[scale=0.8, x=2cm, y=2cm, axis/.style={ ->, >=stealth'}]
draw[dotted, xstep=1cm, ystep=1cm] (-1.9,0) grid (1.9,3.9);
draw[axis] (-2,0) -- (2,0) node[above] {small $x$};
draw[axis] ( 0,0) -- (0,4) node[right] {small $y$};
%
foreach x/xtext in {-2/-2, -1/-1, 0/0, 1/1}
draw[shift={(x,0)}] (0pt,2pt) -- (0pt,-2pt) node[below, fill=white] {small xtext};
foreach y/ytext in {1/1, 2/2, 3/3}
draw[shift={(0,y)}] (2pt,0pt) -- (-2pt,0pt) node[left, fill=white] {small ytext};
% functions
draw[color=red, thick] plot[domain=-2:2, samples=250]
(x,{x*x}) node[right] {small $f(x)$};
end{tikzpicture}
end{center}
end{document}


Answered by Zarko on September 30, 2020

## Related Questions

### Automatic line break in tabularx environment

1  Asked on December 5, 2020 by lourdesriquelme

### Synctex and Environments

1  Asked on December 5, 2020 by meneldur

### pgfplotstable: create style by a loop

0  Asked on December 5, 2020

### How to allow # in newcommand without # or another way to defer processing of section of code

4  Asked on December 5, 2020 by ctrl-alt-delor

### Define a macro that generates a macro that takes in arguments

3  Asked on December 4, 2020 by kelvin-lee

### Include .Rtex as a chapter in latex

1  Asked on December 4, 2020 by cianius

### where, how, and when to load xcolor options

2  Asked on December 4, 2020

### Multirow and Two Lines in One Cell on Table

1  Asked on December 4, 2020 by lis

### Key values using l3keys (pencil symbol)

1  Asked on December 4, 2020

### Draw perpendicular arrows in TikZ

2  Asked on December 4, 2020 by paulfligtht

### Mixed decimal input with siunitx

2  Asked on December 4, 2020 by hobbicon

### Incompatible versions of luatex problem

0  Asked on December 4, 2020 by peter-flom

### problems finding correct language.dat

1  Asked on December 4, 2020

### Question about “concert” format in Appendix E of TeXbook

0  Asked on December 4, 2020

### scrlttr2 – Change Fontstyle for the whole document

1  Asked on December 4, 2020 by woulterm

### Aligning Multiple authors in the same line in IEEEtran

1  Asked on December 4, 2020 by r-arvind

### How to automatically use typewriter font in arrays?

2  Asked on December 4, 2020 by nilsk

### Minipage in table has strange inter-row spacing

2  Asked on December 4, 2020

### Process bibitem without year data in an elsarticle-harv reference list

0  Asked on December 4, 2020 by wklchris