LyXAccess to the toc file

Information and discussion about LyX, a WYSIWYM editor, available for Linux, Windows and Mac OS X systems.
Post Reply
dyaku
Posts: 1
Joined: Sat Jun 15, 2024 3:42 pm

Access to the toc file

Post by dyaku »

Hi everyone,
I have a master document for my class with a "if" statement to exclude parts (one version for my students, one for myself). My goal is to have the full Toc in the student version even if the section don't appear in the document (done in class).
Here's a way to do it in latex with this example:

Code: Select all

\documentclass[10pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{hyperref}
\let\Contentsline\contentsline
\renewcommand\contentsline[3]{\Contentsline{#1}{#2}{}}


\newif\ifall
\allfalse

\begin{document}
\ifall
	\tableofcontents
\else
	\makeatletter
	\input{toc_if_copy.toc}
	\makeatother
\fi


\section{Section is always there}
\begin{figure}[!h]
\caption{fig A}
\end{figure}
\ifall
\section{Section is optional}

\begin{figure}[!h]
\caption{fig B}
\end{figure}
\fi
\section{Section is always there}
\begin{figure}[!h]
\caption{fig C}
\end{figure}
\end{document}
1) I compile it with \alltrue. Save the *.toc in a file named `toc_if_copy.toc`.
2) Compilation with \allfalse.

Is there a way to do it with Lyx? It's my favourite editor.
Thanks!

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics
Post Reply