7

I would like to use an environment that makes everything inside... invisible! I would like that during the .tex compilation to read everything but not render some parts of my LaTeX document.

The problem of \begin{comment} ... Is that the code inside is not "read". I know my problem is unusual, but in fact I want the code inside to be read (it will generate a file), but I don't want it to be rendered (it normally write lines and lines of codes I don't want)

The problem of \phantom is that it is still "rendered" as a blank rectangle. If I do that I have a huge blank space

(In fact, I want to use SageTex, which "mix" SageMath and LaTeX. There is a way to write a sage code directly in the .tex file. You have to compile with LaTeX the document. It will produce a .sage document, that I have to compile with sage this time. Finally, I have to compile with LaTeX so that the Sage calculations are "understood" by LaTeX. For example I can write a sage code "x = 2 + 2", and use $\sage{x}$, it will render 4. But my problem is that by doing that, it always render first verbatim "x = 2 + 2". And I don't want to see that. I want my calculations to be hidden, not rendered, such that, at viewing the .pdf we can't determine if sage was used or not)

Simple example :

\usepackage{sagetex}
\begin{document}
%\begin{comment}
\begin{sageblock}
U = 12
\end{sageblock}
%\end{comment}
U = $\sage{U}$
\end{document}

I want a simple render "U = 12" in a "LaTeX way". With this I have it two times. Once in a "sage code way", and once the well-rendered "LaTeX way"

The solution of StefanH :

\newcommand\donotshow[1]{\smash{\vphantom{#1}}}

Seems to work well, but I still have an error. I think it's because I don't want to use only \donotshow{something} but \donotshow{ an environment, with multiple lines}

  • So you want to have only the side effects of typesetting (like macro definitions, counter changes etc), but not the typeset output? – gernot Nov 5 '16 at 12:47
  • 1
    It might be worth to explain the background of your problem. Maybe there is another/better way to achieve what you want. Use the edit button left below your posting to add it. E.g., if the original task is to mix code and its documentation, then you can look at the way how LaTeX packages are distributed as dtx files, from which the style file as well as its manual can be generated. – gernot Nov 5 '16 at 12:58
  • Not sure whether this meets your requirements. Do you know about the filecontents environment (standard LaTeX)? Anywhere before \begin{document} you can use \begin{filecontents}{somefile.txt} Some text written to a file named somefile.txt. \end{filecontents} to write stuff to external files. – gernot Nov 5 '16 at 13:07
  • OP, you seem to have 2 accounts, you should contact a moderator to get them merged, then you'll be able to edit your posts and interact with the site properly, earn rep, that kind of thing :) – Au101 Nov 5 '16 at 13:42
6

Use the sagesilent environment instead of sageblock. According to the sagetex manual,

this environment is like sageblock, but it does not typeset any of the code; it just writes it to the .sage file. This is useful if you have to do some setup in Sage that is not interesting or relevant to the document you are writing.

3

The comment package provides an environment comment to remove parts of the code from the output:

\documentclass{article}
\usepackage{comment}

\begin{document}
This text will be output.
\begin{comment}
And that won't.
\end{comment}
\end{document}

which results in

This text will be output.

  • To be precise, the comment environment removes the code from the input, i.e., it is not typeset, at least not in normal terms. So it will not be invisible (occupying still space), but non-existent. – gernot Nov 5 '16 at 12:31
3

Maybe not the nicest solution, but you can use \vphantom to get a box of no horizontal space and the same vertical distance as the content, then removing it with \smash.

\documentclass{article}
\usepackage[nopar]{lipsum}
\newcommand\testA{\textbf{AAA}}
\newcommand\donotshow[1]{\smash{\vphantom{#1}}}
\begin{document}
\testA
\lipsum[1]
\textbf{[HERE]}
\donotshow{%
  Test of renewing commands
  \gdef\testA{\textbf{BBB}}
}%
\lipsum[2]
\testA
\end{document}

At the point of [HERE] some text is vanished together with a redefinition of \testA. I use \gdef since, to my knowledge, there is no global version of \renewcommand.

enter image description here

2

You can make small parts of text or math vanish by using \phantom (standard TeX). For larger parts you can make the text transparent, using \transparent{0} from the transparent package. The vanished parts are just invisible, but will still occupy space.

\documentclass{article}
\usepackage{transparent}
\newcommand\somestuff
  {Some sample text different from lipsum.
   \begin{equation}
     x = 1 + \phantom{2} + 3
   \end{equation}
   Some sample \phantom{text} different from lipsum.
  }
\begin{document}
\somestuff

{\transparent{0}%
\somestuff

}
\somestuff
\end{document}

enter image description here

  • 1
    interesting. the "transparent" portion can be cut-and-pasted from the pdf file, whereas the "phantom" stuff (obviously) can't. what's more, depending on how the cut-and-paste is "highlighted" on the pdf image, the ff-ligatures may be unligatured after pasting. none of that is mentioned in the documentation -- it probably should be. – barbara beeton Nov 5 '16 at 12:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.