I need to create and save latex drawing so i can use there else where.
Im using the code
\begin{tikzpicture}[scale=0.8,domain=-2:20]
\begin{axis}[
height = 11.7cm,
width = 15cm,
axis lines=middle,
grid=major,
xmin=-2,
xmax=10,
ymin=-2,
ymax=20,
y label style={at={(axis description cs:0.5,-0.05)},anchor=north},
x label style={at={(axis description cs:-0.05,.5)},rotate=0,anchor=south},
xlabel=$y$,
ylabel=$x$,
xtick={-2,-1,0,...,14},
ytick={-2,0,...,20},
tick style={very thick},
legend style={
at={(rel axis cs:0,1)},
anchor=north west,draw=none,inner sep=0pt,fill=gray!10}
]
\addplot[black,thick,samples=1] {0};
\draw[color=red, smooth] plot (\x,\x*\x-8*\x+16) node[above left] {$y = 3$};
\draw (4,1.5) node[anchor=north]{(4,0)};
\draw (1.2,16) node[anchor=east]{(0,16)};
\draw (7,8) node[anchor=west]{$y=x^2-8x+16$};
\end{axis}
\end{tikzpicture}
and i want to save the image it creates as a png. I need to create multiple of these with differences to each image. So i need to create all the images with the exact scale and size so doing a screenshot of the page is not good enough.
From the comments I have developed the code including the preamble from my original document.
\documentclass[tikz,convert]{standalone}
\usepackage[colorlinks=true]{hyperref}
\usepackage[english]{babel}
\usepackage[utf8x]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amsfonts}
\usepackage{graphicx}
\usepackage[subpreambles=true]{standalone}
\usepackage{import}
\usepackage{mathtools}
\usepackage{tkz-euclide}
\usepackage{bigints}
\usetkzobj{all}
\usepackage{verbatim}
\usepackage{array}
\usepackage{float}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{siunitx}
\usepackage{gensymb}
\usepackage{xlop}
\usepackage{color,soul}
\usepackage[colorinlistoftodos]{todonotes}
\usepackage[a4paper,top=3cm,bottom=2cm,left=3cm,right=3cm,marginparwidth=1.5cm]{geometry}
\usetikzlibrary{intersections}
\sisetup{output-decimal-marker={,}}
\pgfplotsset{compat=1.14}
\setlength\parindent{0pt}
\setlength{\parskip}{2em}
\renewcommand{\arraystretch}{1.9}
%need for table solutions
\usepackage{xcolor}
\CorrectChoiceEmphasis{\color{red}}
\setlength\fillinlinelength{1cm}
\setlength\answerclearance{0.5ex}
\newcommand{\NN}{\mathbb{N}}
\newcommand{\ZZ}{\mathbb{Z}}
\newcommand{\CC}{\mathbb{C}}
\newcommand{\RR}{\mathbb{R}}
\newcommand*\circled[1]{\tikz[baseline=(char.base)]{\node[shape=circle,draw,inner sep=2pt] (char) {#1};}}
\newcommand{\sinth}{\sin(\theta)}
\newcommand{\costh}{\cos(\theta)}
\newcommand{\tanth}{\tan(\theta)}
\newcommand{\secth}{\sec(\theta)}
\newcommand{\cosecth}{\cosec(\theta)}
\newcommand{\coshth}{\cosh(\theta)}
\newcommand{\sinhth}{\sinh(\theta)}
\newcommand{\tanhth}{\tanh(\theta)}
\DeclareMathOperator{\sininv}{sin^{-1}}
\DeclareMathOperator{\cosinv}{cos^{-1}}
\DeclareMathOperator{\taninv}{tan^{-1}}
\theoremstyle{definition}
\newtheorem{exercise}{Exercise}[section]
\theoremstyle{definition}
\newtheorem{example}{Example}[section]
\begin{document}
\begin{tikzpicture}[domain=-2:20, range=-2:10]
\begin{axis}[
axis lines=middle,
grid=major,
xmin=-2,
xmax=10,
ymin=-2,
ymax=20,
y label style={at={(axis description cs:0.5,-0.05)},anchor=north},
x label style={at={(axis description cs:-0.05,.5)},rotate=0,anchor=south},
xlabel=$y$,
ylabel=$x$,
xtick={-2,-1,0,...,14},
ytick={-2,0,...,20},
tick style={very thick},
legend style={
at={(rel axis cs:0,1)},
anchor=north west,draw=none,inner sep=0pt,fill=gray!10}
]
\addplot[black,thick,samples=1] {0};
\draw[color=red, smooth] plot (\x,\x*\x-8*\x+16) node[above left] {$y = 3$};
\draw (4,1.5) node[anchor=north]{(4,0)};
\draw (1.2,16) node[anchor=east]{(0,16)};
\draw (7,8) node[anchor=west]{$y=x^2-8x+16$};
\end{axis}
\end{tikzpicture}
\end{document}
This creates my graph but not in the centre of the page and the graph goes over the page.
Using the code given below for the equation when it works perfectly. However if i try and do another graph it goes over the page.
\documentclass[tikz]{standalone}
this will produce a pdf of the size of the tikz graph. If you use theconvert
options ofstandalone
appropriately, you can create automatically a png of the same page size.