0

I use the exam document class in AUCTeX to write exams for my students. I want to use the features provided by the outline-minor-mode to hide all the exercises I have finished and only show the one I am editing. In the exam class there is \question macro for writing exercises. Here is an example :

\documentclass{exam}
\begin{document}
\begin{questions}
\question % exercise N°1
     statement of exercise 1
\question % exercise N°2
    statement of exercise 2
\question % exercise N° 3
     statement of exercise 3
\end {questions}
\end{document}

I want for example to hide the statements of exercise 1 and 3 when I edit the statement of exercise 2! So I have add \question to the heading list of AUCTeX with the variable TeX-outline-extra like this: M-x (setq TeX-outline-extra '(("\question" 1))) But \question is not recognized as a heading as expected!

1

this answer is given by @Tyler in this post

http://emacs.stackexchange.com/questions/27829/how-to-use-outline-minor-mode-to-hide-some-exam-class-exercises-in-auctex/27880#27880

You haven't properly escaped the regexp for "\question". It should be:

"\\\\question\\b"

This is a string, and in order to encode a single backslash in a string, it needs to be escaped with a backslash of its own. And in order to use a literal backslash in a regexp, it must be escaped with another backslash. So to get a regexp to match a single literal \ from a string, you need to use \\\\.

The \\b at the end of the string matches the end of a word, which is the regexp \b.

This will only work if \question appears at the beginning of the line. That's why @arashesbati added the [ \t]*, which makes the regexp match \question with any number of tabs or spaces before it on a line.

Setting the outline level to 1 seems a bit high, I think you might end up folding everything below the question into the question, including subsequent sections. So probably more useful to use something like:

("[ \t]*\\\\question\\b" 4)

Finally, it looks like AucTex only reads this at the beginning of a session, and subsequent changes to take effect until you restart. So the best way to make this addition is probably via M-x customize-variable TeX-outline-extra. That way, you know the variable will be changed before AucTex is loaded the next time you start Emacs. In my case, this variable is defined as:

'(("[   ]*\\\\question\\b" 4) ("[   ]*\\\\\\(bib\\)?item\\b" 7) ("\\\\bibliography\\b" 2))

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.