1

I have a big file having the following structure :

\begin{exo}
...
\end{exo}

\begin{exo}
...
\end{exo}

My aim is to create different files containing just one exercice. How can I do this ? Does there exist a software ?

jowe_19
  • 939
  • It should be easy enough to split out the exercises from LaTeX itself, defining {exo} in imitation of {filecontents}. But what about the file naming? – Donald Arseneau Jun 14 '20 at 21:21
  • 1
    Finally I used a Python script to do this. But thanks for your suggestion. – jowe_19 Jun 16 '20 at 09:19
  • Two links which can help you. This one explains how to use LuaTeX to obtain different .tex files from the original one an this answer explains how to use tcolorbox to extract contents from one file to other ones which can be later on included or just leaved for independet processing. The second solution could be applied redefining your exo enviroments. – Ignasi Nov 12 '20 at 09:49
  • @jowe_19 Can you post your python script as an answer. – Krishna Jul 30 '23 at 23:51

3 Answers3

1

Emacs users can perform this function.

(defun save-environments (env)
  "Collects all the ENV environments (default to EXO) to save them each in a separate file. Replaces each with an \input"
  (interactive
   (list (read-string "Environment: " "exo")))
  (with-current-buffer (buffer-name)
    (let ((env-number 0)
          (file-se (file-name-sans-extension (buffer-name))))
      (goto-char (point-min))
  (while
      (search-forward  (format"\\begin{%s}" env) nil t)
    (setq env-number (1+ env-number))
    (LaTeX-mark-environment)
    (kill-region (point) (mark))
    (with-temp-file (format "%s-%s-%d.tex" file-se env  env-number)
      (goto-char (point-min))
      (insert (format "%% %s-%s-%d.tex\n" file-se env env-number)
              (format "%% From %s.tex \n\n" file-se))

      (yank))
    (insert (format "\\input{%s-%s-%d}\n" file-se env env-number))))))

It can be used for any environment, default is exo.

gigiair
  • 1,812
0

You could use standard latex functionality such as the import libraries and manually split up exercises into individual files. And then use either import with relatives paths via subimport, use just use the full path.

How to use the import package?

I think the main issue would be getting all the commands into separate files.

However if you wish to automatic this process, you may need to use a scripting language like python and do something similar to web scrapping using a tool like TexSoup

  • 1
    I think this is the contrary of what the OP asked. S/He has a unique file and wants to create many files. – CarLaTeX Feb 20 '19 at 20:18
0

That is not really an answer but this can help you.

I have used the following pieces of code to manage a lot of questions written in different files.

\documentclass[10pt]{beamer}

\usepackage{pgffor} \newcommand\nbquest{16}

\newcommand\dirofquest{01-no-parabola}

\begin{document}

\foreach \n in {1,...,\nbquest}{ \begin{frame} \frametitle{Question FLASH no. \n}

    \Large\centering

    \input{\dirofquest/question-\n.tex}
\end{frame}

}

\end{document}

projetmbc
  • 13,315
  • I think this is the contrary of what the OP asked. S/He has a unique file and wants to create many files. – CarLaTeX Dec 07 '21 at 15:07