5

I'm writing my lessons on a big LaTeX document so, I've each chapter on a dedicated LaTeX file (which are imported by import command)

However, for some lessons, I want to set a "cotation table" (or other stuff for teacher and not for students) who can't be visible for my students. I don't want to comment and uncomment this table on each .tex files so I prefer a dedicated section on the main LaTeX file I'll comment if I want to see this section or not and ideally, I don't want to change the page order of my document. (so I'm able to point the same page for me or my students).

Taking this into account, is it possible to put in braces the part of a code in the corresponding .tex chapter to make it appear on a dedicated section at the end of my syllabus ? So if the dedicated section is comment in the main files, the part of code on each .tex files will be ignored and if this section is uncomment, these stuffs will be printed at the end.

A MWE will be something like that :

\documentclass[11pt,a4paper]{report}
\usepackage[latin1]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{lipsum}


\begin{document}
    \chapter{1st chapter}
    \section{My lesson}
        \lipsum[1-2]

        %{start of the teacher part}
    \subsection{Stuff for teacher}
        \label{TeacherStuff}
        \lipsum[1]
        %{end of the teacher part}

    \subsection{My lesson for students continues}
        \lipsum[1]

    \chapter{2nd chapter}
        \lipsum[1]

    \chapter{dedicated chapter for teacher's stuff}
        Where the subsection \ref{TeacherStuff} has to appear.
\end{document}

Thanks for your help !

5

It's easy with \AtEndDocument{...} from etoolbox package.

To have a teacher/students versions, I've created a boolean \newbool{studentversion}: if you set it to false \setbool{studentversion}{false}, you got the teacher version and vice versa; and two commands: \mypart{...} two write the teacher's parts and \myend{...} to hide the final chapter title in case of student version.

\documentclass[11pt,a4paper]{report}
\usepackage[latin1]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{lipsum}
\usepackage{etoolbox}
\newbool{studentversion}
\setbool{studentversion}{false}%true for studtents' version 
\newcommand{\mypart}[1]{\ifbool{studentversion}{}{\AtEndDocument{#1}}}
\newcommand{\myend}[1]{\ifbool{studentversion}{}{#1}}
\begin{document}
    \chapter{1st chapter}
    \section{My lesson}
        \lipsum[1-2]

        %{start of the teacher part}
        \mypart{%
    \subsection{Stuff for teacher}
        \label{TeacherStuff}
        \lipsum[1]
        %{end of the teacher part}
}
    \subsection{My lesson for students continues}
        \lipsum[1]

\mypart{%
    \subsection{Some other stuff for teacher}
        \label{otherTeacherStuff}
        \lipsum[1]
        %{end of the teacher part}
}

    \chapter{2nd chapter}
        \lipsum[1]

\mypart{%
    \subsection{Some other stuff for teacher again}
        \label{otherTeacherStuffagain}
        \lipsum[1]
        %{end of the teacher part}
}
\myend{%
    \chapter{dedicated chapter for teacher's stuff}
        Where the subsection \ref{TeacherStuff} has to appear.
    }
\end{document}
  • It worked perfectly to write at the end but if i want to ignore these sections without comment each \AtEndDocument{} ? Is there a way (an option maybe, i'm reading the documentation of etoolbox package) ? Or if i want to add index more at the end of the document, is it possible to force the place where the etoolbox package will put these parts ? – Piroooh Mar 10 at 10:03
  • @Piroooh See my renewed answer and please let me know if it's OK. – CarLaTeX Mar 10 at 10:29
  • it's compatible with my files and documents. Very convenient answer ! I've one last question : If i want to keep some parts (like index) at the very end of my document. Is it possible to set the place where \AtEndDocument{} will act ? I saw in the documentation of the etoolbox package that AfterEndDocument is executed after but i'm not sure if i can use it for a \makeindex. I'm testing it. EDIT : I just have to set \printindex on \AtEndDocument. Perfect answer. Thanks @CarLaTeX – Piroooh Mar 10 at 10:56

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.