2

I'm typesetting a drawing for an assignment, but I can only change what's in \begin{document} -- that is, I can't add any packages or make any changes in the preamble. Unfortunately, the platform I'm working on doesn't have tikz or pgfplots installed, so is there a way I can make basic drawings without using either package? (e.g. drawing squares and points)

Brian Lee
  • 433

1 Answers1

3

Assume the following:

  • xcolor is in your preamble, or you know how to define \colorlet;
  • you can copy files to the working directory (the one that \includegraphics will search in),

Then you can still \input necessary PGF files manually. For example

\documentclass{article}
\usepackage{xcolor}
\begin{document}

\def\ProvidesPackageRCS#1$#2${}
\def\ProvidesFileRCS#1$#2${}
\long\def\AtBeginDocument#1{}
\def\RequirePackage#1{}
\def\EveryShipout#1{}
\makeatletter
\input{pgfutil-common.tex}
\input{pgfutil-latex.def}
\input{pgfsys.code.tex}
\input{pgfcore.code.tex}
\input{pgfsyssoftpath.code.tex}
\input{pgfsysprotocol.code.tex}
\input{pgfcorepathconstruct.code.tex}


A rectangle
\pgfpathrectangle{\pgfpoint{-60pt}{-5pt}}{\pgfpoint{60pt}{20pt}}
\pgfsetcolor{red}\pgfusepath{draw}
\pgfsetcolor{black}

$$$$

A point
\pgfpathcircle{\pgfpointorigin}{5pt}
\pgfusepath{fill}

$$$$

A curve
\pgfpathmoveto{\pgfpointorigin}
\pgfpathcurveto{\pgfpoint{10pt}{10pt}}{\pgfpoint{20pt}{-10pt}}{\pgfpoint{30pt}{00pt}}
\pgfusepath{draw}


\end{document}

You can further input TikZ if necessary.

\input pgffor.code.tex

A lot of points
\par\foreach\n in{1,...,200}{
    \xdef\n{\n}
    \pgfmathsetmacro\x{cos(\n r)*sqrt(\n)*10+200}\xdef\x{\x}
    \pgfmathsetmacro\y{sin(\n r)*sqrt(\n)*10-100}\xdef\y{\y}
    \pgfpathcircle{\pgfpoint{\x pt}{\y pt}}{2pt}
}
\pgfusepath{draw}

\vskip300pt

\input pgfmoduleplot.code.tex
\input tikz.code.tex

A plot
\tikz\draw[scale=3,domain=0:4,samples=300]plot({cos(3*\x r)},{sin(5*\x r)});

Symbol 1
  • 36,855
  • I believe you forgot \makeatother after \inputting the pgf files. – campa Mar 12 '18 at 15:14
  • @campa, it is not needed as well as \makeatletter is superfluous. – Zarko Mar 12 '18 at 15:33
  • @Zarko You were right. I added it when I was searching for the shortest list of \input --- some files are supposed to be included by the root so they do not bother to make at letter again. – Symbol 1 Mar 12 '18 at 15:35
  • @Zarko I am not convinced. The first included file alone redefines the catcode of @. If I take the code in the answer and remove \makeatletter and add a macro \fo@ I get the error Undefined \fo@ and not undefined \fo, which clearly indicates that @ is still considered a letter. Unless of course I am greatly misunderstanding something. – campa Mar 12 '18 at 15:40
  • @campa, sorry but this i can't find in answer code. probably i miss something. also i didn't test the solution (since i'm sure that shoved images are produced with this code. – Zarko Mar 12 '18 at 15:49