0

I would like to add a TikZ design element to a collection of documents. Presently, I accomplish this using a .sty file. More specifically, I build a style file, in this case called homework.sty, wherein I issue the package call \usepackage{tikz} and define the TikZ picture together with a call-command, \logo, that accepts a document title as its argument:

\usepackage{tikz}

\newcommand{\logo}[1]{%
  \begin{tikzpicture}[scale=.5]
    \draw [fill=gray!30] (0,0) rectangle (1,1);
    \draw (.5,-.5) rectangle (1.5,.5);
    \draw [fill=gray] (.5,0) rectangle (1,.5);
    \node [right] at (2,.3) {\LARGE #1};
  \end{tikzpicture}
}

When writing a homework sheet, I then invoke the homework package and apply the logo thusly:

\documentclass{article}
\usepackage{homework}

\begin{document}

\logo{Sine \& Cosine} % the title is different for each homework sheet

\end{document}

Of course, this protocol loads TikZ (and all of its bulk) for every homework sheet. My question is thus: can the same result be accomplished in a way less cumbersome to compilation? I've contemplated exporting the TikZ graphic to postscript and using includegraphics, but that appears to be a finicky routine (see Export eps figures from TikZ). Moreover, inclusion of postscript (in my experience) itself belabors compilation, and requires the image to be stored in every homework sheet folder...

  • Is the logo the same for every files? If yes, the better solution is to create a pdf file for the logo (use standalone to draw it, for example) and then save it and the sty file containing the definition of \logo command into a local tex folder so every user could load the package.
  • – Sigur Feb 07 '15 at 20:25
  • What's wrong with loading TikZ ? Do you have restrictions? Is PGF enough? – percusse Feb 07 '15 at 20:27
  • @Sigur Yes, the logo is the same for every file and, after a glance at the standalone documentation, your recommendation seems promising. Would you mind explicitly demonstrating how to proceed with my MWE? – steven_nevets Feb 07 '15 at 20:39
  • @percusse There's nothing inherently wrong with loading TikZ, per say, but I do observe a good deal of associated material in the output report. Perhaps its effect on compiling-time is minimal and does not warrant my concern, but I just wondered if there was a "lighter" approach. – steven_nevets Feb 07 '15 at 20:50
  • So the argument you are passing to \logo{} doesn't vary at all? If not, why define the command to require one? – cfr Feb 07 '15 at 21:48
  • @cfr The argument of \logo{} is the title of the document and is different for every homework sheet. Only the picture remains the same. – steven_nevets Feb 07 '15 at 22:15
  • So you can use the standalone method to produce the image, but then you would have to position the text over the image in your document. Obviously, if you include an argument when generating the PDF, that argument will be fixed. – cfr Feb 07 '15 at 22:19
  • Given that the MWE takes less than half of one second CPU time on my system, despite loading TiKZ, I have to wonder whether there is anything to be gained here. Reading in an external image also takes resources, after all. – cfr Feb 07 '15 at 23:06
  • @cfr If I used standalone, I would define a \logo command (as in my MWE) to lay the title next to the image. However, I'm having trouble understanding how to use standalone in conjunction with my existing style file. – steven_nevets Feb 07 '15 at 23:34
  • You don't use it in conjunction with it. You just use standalone to create a PDF containing the image and then include it with \includegraphics{}. – cfr Feb 08 '15 at 00:11
  • @cfr If I modified my style-level \logo command to incorporate the \includegraphics and title option, where would the pdf be kept? – steven_nevets Feb 08 '15 at 00:24
  • You can keep it somewhere in your personal TEXMF tree. For example, as $(kpsewhich -var TEXMFHOME)/tex/latex/images/logo.pdf (if you are using TeX Live on a Unix-like system). – cfr Feb 08 '15 at 00:46
  • @cfr I've successfully created a pdf crop of the image using standalone, and incorporated it into a homework sheet using \usegraphicx and \includegraphics. It compiles using LaTeX->pdf but not LaTeX->DVI. Any suggestions? – steven_nevets Feb 09 '15 at 23:29
  • No. You don't want to include postscript images because that slows compilation, and you do not want to compile the images each time because that slows compilation, and you want to use LaTeX to produce DVI. As far as I know, those desiderata are simply incompatible. LaTeX needs postscript images - it cannot use PDF or PNG or.... So if you need LaTeX, you have 2 options: compile the images each time; compile postscript versions and include those. Since you want neither, no, I'm sorry but I have no further suggestions. – cfr Feb 10 '15 at 00:30
  • @cfr Understood. I'd not intended to pose a question with intractable constraints, so I thank you for your patient assistance. – steven_nevets Feb 10 '15 at 01:49
  • @cfr That's an exquisite application of the word "desiderata", btw. ;-) – steven_nevets Feb 10 '15 at 01:59
  • Sadly, such things are often incompatible ;). – cfr Feb 10 '15 at 02:00