0

Is there an optionnal argument to compile only a given section ? I would like to write

\section[OnlyThisSection]{My section} ...

which would allow me to compile only the section I am working on.

It's for a book class. All chapters are in different files, but there are many sections and subsections in each chapter.

  • 1
    If you have your sections in separate files, you can use TeXBlend to compile particular files. – michal.h21 Feb 27 '24 at 16:35
  • Can you a) add which class you use and b) clarify if you have all your code in one file or if you have separate files for your sections. – samcarter_is_at_topanswers.xyz Feb 27 '24 at 16:36
  • 2
    To follow up on samcarter, if the section is in a separate file, you can use \include/\includeonly. It will introduce a page break at that point in your main document. (\section does have an optional argument, but it does something else.) – Teepeemm Feb 27 '24 at 16:42
  • 2
    Note that you have to complile the whole document using \include before you can start using \includeonly to compile specific files. It uses stored aux files for labels etc. – John Kormylo Feb 27 '24 at 16:48
  • @Arthur If you can move your section to a separate file, you could compile only this section via, e.g. the subfiles package or the above mentioned \includeonly. – samcarter_is_at_topanswers.xyz Feb 27 '24 at 16:52
  • 1
    Thank for yout answers. I am already using separeted files, and I am looking for something that do not need change of structure. I am just looking for a small "hack" to improve my efficiency in wrinting latex, if it is possible ! – Arthur Feb 27 '24 at 16:56
  • 2
    Maybe there is some other approach to speed up your compilation. Can you tell us what makes your document slow? Does it have many images? – samcarter_is_at_topanswers.xyz Feb 27 '24 at 16:58
  • this is exactly what \include is designed for, – David Carlisle Feb 27 '24 at 17:50
  • LaTeX has some packages that might help (or not). I find that the subfiles package allows subfiles that, in turn, contain other subfiles. The subfiles do not need to begin a new page in the main document (although they will, if compiled alone). But of course, a subfile has no knowledge of what its numbering should be, because it does not see the non-compiled content. Or, as @DavidCarlisle noted, use \include as the direct approach. – rallg Feb 27 '24 at 19:03
  • 1
    @samcarter_is_at_topanswers.xyz In my experience, even with a lot of experience optimizing things, LaTeX can still be "just slow". I know all of the tricks in compiling - Speeding up LaTeX compilation - TeX - LaTeX Stack Exchange, and yet some of the documents can just take minutes to compile. – user202729 Feb 27 '24 at 20:42
  • @Arthur Can you explain what do you mean by "change of structure"? Do you mean that you don't want to split one file into different files, one for each subsection? – user202729 Feb 27 '24 at 20:42
  • 1
    @user202729, yes I dont want to have a fil per section. – Arthur Feb 27 '24 at 21:35
  • 1
    Compilation is not so long (as I am already using subfiles), but I was thinking that it could be efficient, when just working on a specific section, to just compile this section. And when I work on the next session, juste change a keyword to compile only this new section and so on. – Arthur Feb 27 '24 at 21:41

1 Answers1

0

What I've done with my big project is to have a separate file justOneSection.tex. It and my main.tex start with the same

\documentclass{book}
\input{header}
\begin{document}

After that, main.tex \includes its files, while justOneSection.tex \inputs just one section.

Teepeemm
  • 6,708