TransWikia.com

How to split a sheet of exercises in different files, one file containing just one exercise?

TeX - LaTeX Asked on April 23, 2021

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 ?

3 Answers

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

Answered by GrandFleet on April 23, 2021

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}
newcommandnbquest{16}

newcommanddirofquest{01-no-parabola}

begin{document}

foreach n in {1,...,nbquest}{
    begin{frame}
        frametitle{Question FLASH no. n}
    
        Largecentering
    
        input{dirofquest/question-n.tex}
    end{frame}
}

end{document}

Answered by projetmbc on April 23, 2021

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.texn" file-se env env-number)
                  (format "%% From %s.tex nn" 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.

Answered by gigiair on April 23, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP