如何中和TikZpicture編碼而不刪除它們?

如何中和TikZpicture編碼而不刪除它們?

我有一個文檔,其中包含一百多個與下面看到的類似的 tikz 圖片。

我想(如果可能的話,很容易)從該組代碼生成兩個不同的文檔——(1)原樣; (2) 除了 tikz 圖片之外的所有內容。

我知道我可以複製文件程式碼,然後手動刪除所有 100 多個 tikzpictures——但我希望有更好的方法來產生我正在尋找的內容。

考慮代碼:

\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}

其產生:

在此輸入影像描述

在此輸入影像描述

問題:是否有一種(相當簡單的)方法來修改上述程式碼,以便 LaTeX 不執行編碼tikzpicture而僅在輸出中顯示文字? (我用 編譯程式碼pdflatex。)

謝謝。

答案1

使用套件environ和命令\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}

答案2

我不確定它是否會產生附帶影響,我現在無法進行廣泛測試,但它在 MWE 中有效:添加

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

就在之前\begin{document}。它基本上重新定義了tikzpicture環境,使其無所事事。

您也可以輕鬆新增“路標”,例如

\RenewDocumentEnvironment{tikzpicture}{o +b}{\par***Removed tikzpicture***\par}{}或類似的東西。

註解掉該行將切換 tikzpicures 的編譯與否。

在此輸入影像描述

相關內容