0

I have got several Tikz pictures whose compilation takes up much time. More generally, I am wondering whether there is a switch that can make a specific environment foo disappear as if the code would not exist, similar in effect to the comment environment.

Basically, given

\begin{foo} Whatever happens here \end{foo} 

I want a switch that makes this environment completely ineffective as if it weren't in the Latex code.

4
  • 7
    You can always redefine environments, like with \RenewDocumentEnvironment{tikzpicture}{+b}{\iffalse#1\fi}{}. But maybe you could provide a use case that better shows what you're after? Do you want to keep the place, for example? Commented Aug 7, 2023 at 20:18
  • 8
    If the pictures don't change often, you could also use tikzes external library Commented Aug 7, 2023 at 20:31
  • ... Unless the external library doesn't work for the particular pictures in question. (Some it works fine for; some not.) You could also put the pictures' code in separate files and load it with a macro you can then easily redefine. E.g. \newcommand* \mypicloader[1]{\input{#1} and \renewcommand* \mypicloader[1]{} which lets you exempt some tikzpictures if you want to. Commented Aug 8, 2023 at 0:04
  • See also tex.stackexchange.com/questions/672685/… Commented Aug 8, 2023 at 17:21

1 Answer 1

1

You can redefine and introduce a switch if you already have plenty of code instances of the same environment. So, expanding on Jasper Habicht's comment, you could do the following:

  • create a switch
  • redefine the environment in question
  • in the redefined environment, enclose a regular environment within an if clause (based on the switch), so it depends on that switch.

LaTeX already has a built-in mechanic to create custom if's. Have a look at this post.

Since you have mentioned tikz in your question, I made an example upon tikzpicture. Here is how to put everything together. Every time you use \tikzpicsfalse you are going to turn off tikz, whereas \tikzpicstrue is going to bring it back.

\documentclass{article} \usepackage{tikz} \newif\iftikzpics \tikzpicsfalse % \tikzpicstrue to turn pictures on \NewEnvironmentCopy{oldtikzpicture}{tikzpicture} \RenewDocumentEnvironment{tikzpicture}{O{}+b}{% \iftikzpics \begin{oldtikzpicture}[#1] #2 \end{oldtikzpicture}\fi}{} \begin{document} X \begin{tikzpicture} \node {A}; \end{tikzpicture} \begin{tikzpicture}[ scale=2, baseline, every node/.style = {draw}, ] \node [transform shape] {B}; \end{tikzpicture} \end{document} 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.