I want to write some Latex code like this, in file main.tex:




\chapter{Chap 1}


\section{Sec 1}

Some summary text.

Some comment.

Real text.

\subsection{Sub 1}


(It doesn't necessarily need to be via \begin/\end, it could also be a single command. Not sure what would be easier and more clean. I thought that begin/end is maybe cleaner.)

When I compile it normally, I want that I see just "Real text." but not the parts in the comments (comment and comment-summary).

I can have another Latex file summary.tex which would import this main.tex file. When I compile this Latex file, I want that I see just the text from comment-summary, i.e. "Some summary text." but not the other parts, esp not the "Real text.". However, I do want to see the section structure and the full table of contents.

Is this possible?

I guess related is the question about how to have comments at all, like here. I guess the comment package is very useful for this. But this just answers how I can ignore the content at all (right?).

I guess when I define comment and comment-summary, I could do it like \ifnotdefined{comment-summary} \define{comment-summary} <ignore it> ... (or however that would work exactly in Latex...). And in summary.tex, I could pre-define comment-summary to not ignore it, but to actually just print it. So that is reasonable straight-forward.

However, that would still leave the "Real text." unchanged. I have no idea how to remove that. Or is that even possible? I thought about going through main.tex but just collect the comment-summary, and write it to a temp file or some variable, and after it went through, just output that. I assume that this is possible, but I have no idea how to do sth like that in Latex.

Maybe this question about commenting out whole sections is related to that. Although it uses strange custom sections, and also I don't want to hide specific sections, but basically everything, and just strip out comment-summary.

Maybe this question about doing the inverse of comment is also very related. But the solution given there is via additional preprocessing and looks specific to tikz.

Note that I have used comment and comment-summary here as an example, where comment would most likely always be removed (unless maybe I want to print just those at some point, who knows...), and comment-summary (and only that) would be for such a summary.tex. But the whole approach should be generic. There can be many variations, like a Latex file where you print everything (verbose mode or so), etc. And you could also add further tags, like comment-todos, etc.

Note that I don't care too much about spacing problems which could arise when I use the comment within part of another paragraph, or in other strange places, as discussed here. In my case, a comment, and a comment-summary, etc, would always be a separate paragraph. I assume in that case, there would not be any problems (right?).

Your Answer

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

Browse other questions tagged or ask your own question.