3

I have a document which contains over one hundred tikzpictures similar to the ones seen below.

I would like to (easily, if possible) produce two different documents from that set of code---(1) as it is; and (2) everything but the tikzpictures.

I know that I could copy the document code and then manually delete all 100+ tikzpictures---but I am hoping there is a better way to produce what I am looking for.

Consider the code:

\documentclass[a5paper,12pt,openany]{book}
\usepackage[paperwidth=5.5in,paperheight=8.25in]{geometry}
\textwidth=4.25in \textheight=7.0in \voffset -7pt

\usepackage[tracking=true]{microtype}
\usepackage{tikz,lipsum} \usepackage{mathptmx} \definecolor{lightblue}{RGB}{197,213,255}

\begin{document} \thispagestyle{empty} \parskip 10pt \lipsum[13]

\begin{center} \begin{tikzpicture}[pencildraw/.style={ % decorate, decoration={random steps,segment length=4pt,amplitude=2.5pt} } % ] \node[preaction={fill=black,opacity=.7,transform canvas={xshift=1mm,yshift=-1mm}}, %pencildraw, draw,fill=lightblue,text width=0.85\textwidth,inner sep=4mm] {\begin{minipage}{3.42in} \footnotesize \selectfont \textbf{\lipsum[13]} \hfill \textbf{\emph{---L. Iipsum}} \end{minipage}}; \end{tikzpicture} \end{center}

\lipsum[13]

\begin{center} \begin{tikzpicture}[pencildraw/.style={ % decorate, decoration={random steps,segment length=4pt,amplitude=2.5pt} } % ] \node[preaction={fill=black,opacity=.7,transform canvas={xshift=1mm,yshift=-1mm}}, %pencildraw, draw,fill=lightblue,text width=0.85\textwidth,inner sep=4mm] {\begin{minipage}{3.42in} \footnotesize \selectfont \textbf{\lipsum[13]} \hfill \textbf{\emph{---L. Iipsum}} \end{minipage}}; \end{tikzpicture} \end{center}

\lipsum[13]

\begin{center} \begin{tikzpicture}[pencildraw/.style={ % decorate, decoration={random steps,segment length=4pt,amplitude=2.5pt} } % ] \node[preaction={fill=black,opacity=.7,transform canvas={xshift=1mm,yshift=-1mm}}, %pencildraw, draw,fill=lightblue,text width=0.85\textwidth,inner sep=4mm] {\begin{minipage}{3.42in} \footnotesize \selectfont \textbf{\lipsum[13]} \hfill \textbf{\emph{---L. Iipsum}} \end{minipage}}; \end{tikzpicture} \end{center} \end{document}

which produces:

enter image description here

enter image description here

QUESTION: Is there a (reasonably simple) way to modify the above code so that LaTeX does not execute the tikzpicture codings and just the text appears in the output? (I compile the code with pdflatex.)

Thank you.

DDS
  • 8,816
  • 4
  • 9
  • 36
  • You can use e.g. package multiaudience: https://ctan.org/pkg/multiaudience , or other ones from cond-comp: https://ctan.org/topic/cond-comp . E.g. with multiaudience you'd define two groups (of readers) and encapsulate your tikzpictures as needed. Yes, it's a lot of work. // If you want to automate it, I fear you'll need to do some kind of scripting, e.g. to find and delete all these environmenst, and finally save to a second doc. For practical reasons the full version should be the master, and the extract generated as needed dynamically. Consider PERL etc. for this. – MS-SPO Jan 31 '24 at 21:32
  • 1
    You could use standalone to put the tikzpictures into a file by themselves, one per page. Then is is just a decision on whether to include them. See also https://tex.stackexchange.com/questions/423109/export-each-figure-as-a-separate-pdf-file/423253?r=SearchResults&s=11%7C26.9056#423253 – John Kormylo Jan 31 '24 at 21:44
  • @JohnKormylo Thank you for the link; however, my (real) document is in book class. I'm not sure it will work for me. – IdleCustard Feb 01 '24 at 02:13
  • 1
    I tested it and it works fine in book class, but the other solutions are simpler. – John Kormylo Feb 01 '24 at 16:53
  • 1
    @JohnKormylo Thank you. That is good to know. – IdleCustard Feb 01 '24 at 16:59

2 Answers2

4

With package environ and command \RenewEnviron :

\documentclass[a5paper,12pt,openany]{book}
\usepackage[paperwidth=5.5in,paperheight=8.25in]{geometry}
\textwidth=4.25in \textheight=7.0in \voffset -7pt

\usepackage[tracking=true]{microtype}
\usepackage{tikz,lipsum} \usepackage{mathptmx} \definecolor{lightblue}{RGB}{197,213,255}

\usepackage{environ} %change \RenewEnviron{tikzpicture}{}{}

\begin{document} \thispagestyle{empty} \parskip 10pt \lipsum[13]

\begin{center} \begin{tikzpicture}[pencildraw/.style={ % decorate, decoration={random steps,segment length=4pt,amplitude=2.5pt} } % ] \node[preaction={fill=black,opacity=.7,transform canvas={xshift=1mm,yshift=-1mm}}, %pencildraw, draw,fill=lightblue,text width=0.85\textwidth,inner sep=4mm] {\begin{minipage}{3.42in} \footnotesize \selectfont \textbf{\lipsum[13]} \hfill \textbf{\emph{---L. Iipsum}} \end{minipage}}; \end{tikzpicture} \end{center}

\lipsum[13]

\begin{center} \begin{tikzpicture}[pencildraw/.style={ % decorate, decoration={random steps,segment length=4pt,amplitude=2.5pt} } % ] \node[preaction={fill=black,opacity=.7,transform canvas={xshift=1mm,yshift=-1mm}}, %pencildraw, draw,fill=lightblue,text width=0.85\textwidth,inner sep=4mm] {\begin{minipage}{3.42in} \footnotesize \selectfont \textbf{\lipsum[13]} \hfill \textbf{\emph{---L. Iipsum}} \end{minipage}}; \end{tikzpicture} \end{center}

\lipsum[13]

\begin{center} \begin{tikzpicture}[pencildraw/.style={ % decorate, decoration={random steps,segment length=4pt,amplitude=2.5pt} } % ] \node[preaction={fill=black,opacity=.7,transform canvas={xshift=1mm,yshift=-1mm}}, %pencildraw, draw,fill=lightblue,text width=0.85\textwidth,inner sep=4mm] {\begin{minipage}{3.42in} \footnotesize \selectfont \textbf{\lipsum[13]} \hfill \textbf{\emph{---L. Iipsum}} \end{minipage}}; \end{tikzpicture} \end{center} \end{document}

Manuel Cart
  • 541
  • 2
  • 9
3

I am not sure if it can have collateral effects, I can't extensively test now, but it works in the MWE: add

\RenewDocumentEnvironment{tikzpicture}{o +b}{}{}

just before \begin{document}. It basically redefine the tikzpicture environment to do nothing.

You can easily add a "signpost" also, like

\RenewDocumentEnvironment{tikzpicture}{o +b}{\par***Removed tikzpicture***\par}{} or something like that.

Commenting in/out that line would toggle the compilation of tikzpicures or not.

enter image description here

Rmano
  • 40,848
  • 3
  • 64
  • 125