Skip to main content

2.8 Commenting

It is often necessary to comment out temporarily a region of TeX or LaTeX code. This can be done with the commands C-c ; and C-c %. C-c ; will comment out all lines in the current region, while C-c % will comment out the current paragraph. Type C-c ; again to uncomment all lines of a commented region, or C-c % again to uncomment all comment lines around point. These commands will insert or remove a single '%' respectively.

Command: TeX-comment-or-uncomment-region

(C-c ;) Add or remove '%' from the beginning of each line in the current region. Uncommenting works only if the region encloses solely commented lines. If AUCTeX should not try to guess if the region should be commented or uncommented the commands TeX-comment-region and TeX-uncomment-region can be used to explicitly comment or uncomment the region in concern.

Command: TeX-comment-or-uncomment-paragraph

(C-c %) Add or remove '%' from the beginning of each line in the current paragraph. When removing '%' characters the paragraph is considered to consist of all preceding and succeeding lines starting with a '%', until the first non-comment line.

In docTeX document, all documentations are commented out. AUCTeX inserts '%' (with an accompanying space) at the beginning of line when you issue some commands including sectioning (C-c C-s) and inserting environments (C-c C-e), on a commented line. This behavior is controlled by LaTeX-insert-into-comments.

User Option: LaTeX-insert-into-comments

When this option is non-nil, some editing commands are aware of comment prefix at the beginning of line and insert it in the line created anew.

The default value of this option is nil and is set to t in docTeX mode.