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...

17
  • 1. 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 7, 2015 at 20:25
  • What's wrong with loading TikZ ? Do you have restrictions? Is PGF enough?
    – percusse
    Feb 7, 2015 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? Feb 7, 2015 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. Feb 7, 2015 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 7, 2015 at 21:48

1 Answer 1

6

pgf version without TikZ

\documentclass{article}

\usepackage{color}
\usepackage{pgf}

\definecolor{logolightgray}{gray}{.85}% = gray!30
\definecolor{logogray}{gray}{.5}

\newdimen\logounit
\setlength{\logounit}{5mm}

\newcommand*{\logo}[1]{%
  \begin{pgfpicture}
    \pgfpathrectangle{\pgfpointorigin}{\pgfpoint{\logounit}{\logounit}}
    \pgfsetfillcolor{logolightgray}
    \pgfusepath{fill, stroke}
    \pgfpathrectangle{\pgfpoint{.5\logounit}{-.5\logounit}}%
                     {\pgfpoint{\logounit}{\logounit}}
    \pgfusepath{stroke}
    \pgfpathrectangle{\pgfpoint{.5\logounit}{0pt}}%
                     {\pgfpoint{.5\logounit}{.5\logounit}}
    \pgfsetfillcolor{logogray}
    \pgfusepath{fill, stroke}
    \pgftransformshift{\pgfpoint{2\logounit}{.3\logounit}}
    \pgfsetfillcolor{black}
    \pgfnode{rectangle}{west}{\LARGE #1}{logotext}{}
  \end{pgfpicture}
}

\begin{document}
  \logo{Sine \& Cosine}
\end{document}

Result for package pgf

picture version

The drawing is so simple, it can also be done by the picture environment. The only complication is that \framebox puts the line outside the rectangle, whereas pgf/TikZ draws the lines in the middle of the virtual rectangle, half of the line is outside and half of the line is inside. Package picture is loaded to ease the calculations.

\documentclass{article}

\usepackage{color}
\usepackage{picture}

\definecolor{logolightgray}{gray}{.85}
\definecolor{logogray}{gray}{.5}

\newcommand*{\logo}[1]{%
  \begingroup
    \setlength{\unitlength}{5mm}%
    \def\squarefill(##1,##2)##3##4{%
      \put(##1,##2){%
        \makebox(##3,##3){%
          \color{##4}%
          \rule{##3\unitlength}{##3\unitlength}%
        }%
      }%  
    }%  
    \def\squaredraw(##1,##2)##3{%
      \put(##1\unitlength+.2pt,##2\unitlength+.2pt){%
        \framebox(##3\unitlength-.4pt, ##3\unitlength-.4pt){}%
      }%
    }%  
    \begin{picture}(1.5, 1.5)(0, -.5)
      \squarefill(0, 0){1}{logolightgray}
      \squarefill(.5, 0){.5}{logogray}
      \squaredraw(0, 0){1}
      \squaredraw(.5, -.5){1}
      \squaredraw(.5, 0){.5}
    \end{picture}%
    \kern.5\unitlength
    \kern.3333em % inner sep from \node
    \sbox0{\LARGE #1}%
    \raisebox{\dimexpr.8\unitlength-.5\height+.5\depth\relax}{\usebox0}%
  \endgroup
}

\begin{document}
  \logo{Sine \& Cosine}
\end{document}

Result for environment picture

1
  • 1
    (+1) for sheer bloody-mindedness. But I don't really see the point in doing all that just to avoid loading TikZ... ;).
    – cfr
    Feb 8, 2015 at 1:02

You must log in to answer this question.

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