1

Is it possible to write a document where some parts of it are displayed or hidden in the output PDF on the basis of a flag?

What I am tring to do is to write two documents of which one is an extension of the other, one is detailed, the other one is an overview. It is time consuming having to keep what is common among them aligned.

What I would like to do is writing a single document from which I can generates both the overview and the detailed one.

Example:

Source text:

This part is about vitamins, and how healthy they are.

[Detail] This part is about the chemical structure of vitamins.

Output/overview:

This part is about vitamins, and how healthy they are.

Output/detailed:

This part is about vitamins, and how healthy they are.

This part is about the chemical structure of vitamins.

Pietro
  • 123
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Sep 17 '21 at 12:04
  • You probably want to use the comment package. See https://tex.stackexchange.com/questions/17816/commenting-out-large-sections – John Kormylo Sep 17 '21 at 14:21

1 Answers1

1

Since you are using LyX, one option is to use LyX branches. They can be easily toggled on and off. To create a new branch, go to Insert > Branch > Insert New Branch. I two approaches using branches: (1) you can have one branch called "details" and one branch called "overview", and then the shared content would be outside of the branches; or (1) you can just have one branch, e.g., "details" and you can "invert" the branch inset when you want to insert material for only the overview. This way, whenever you "activate" the details branch, the inverted branch insets would be effectively deactivated, and vice-versa.

To toggle whether the branch outputs to PDF, right-click on a branch inset and go to "Activate branch" or "Deactivate branch". Alternatively, you can activate/deactivate in Document > Settings > Branches.

For more information on branches in LyX, see Help > User Guide > 6.9 Branches.

scottkosty
  • 13,164
  • do you know if with the branches approach the chapters are indexed correctly in the table of contents? E.g. if I put a whole chapter in a branch, will the TOC take into account the fact that the branch is enabled/disabled? – Pietro Sep 19 '21 at 15:57
  • 1
    If a branch is disabled, LyX will not even output the contents to LaTeX, and thus it will not show up in the TOC. From LaTeX's point of view, it's the same as if nothing was written. It is a little awkward to work with branches of entire sections in LyX 2.3.x (just getting the selection to insert it into the branch is not intuitive), but this will be improved for LyX 2.4 (hopefully released in early 2022?). – scottkosty Sep 20 '21 at 03:43