In LaTeX, % can be used for single-line comments. For multi-line comments, the following command is available in the verbatim package.

Commented code

But is there a simple command like /* code */ in C?

  • 8
    Related/duplicate: Commenting out large sections Commented Dec 18, 2012 at 7:22
  • 5
    Also see: Block comments in TeX
    – Aditya
    Commented Dec 18, 2012 at 8:03
  • Your question was pretty enough for me.
    – AbdelKh
    Commented Apr 27, 2017 at 23:12
  • 1
    – PlsWork
    Commented Jan 4, 2020 at 15:25
  • 3
    if you are using overleaf, you could try the hotkey Ctrl + / (command + / on a Mac) to toggle commenting for selected lines. (Comment/ uncomment selected text).
    – doplano
    Commented Oct 28, 2021 at 13:41

7 Answers 7


Following the C code paradigm, where one can use the preprocessor directives

#if 0
junk code

something similar can be done in TeX (and descendants):

I don't want this to happen

The commented parts can be easily activated by replacing \iffalse with \iftrue.

  • 2
    @Aditya What would you say is a good and stable way to comment things out? Say, stable in so far as I am not doing anything fancy ---- just commenting out a chunk of code in its plain version. I have also got trouble with block-comment using the \begin{comment} environment, either from the verbatim package or comments package.
    – llinfeng
    Commented Nov 29, 2017 at 12:01
  • 2
    The of @Aditya is dead. Here is the new link: texfaq.org/FAQ-conditional and an archive version: web.archive.org/web/20210813002049/https://texfaq.org/…
    – lyinch
    Commented Feb 23, 2022 at 13:55

A simple solution I use is


Which just defines a command that does nothing with the input (effectively commenting it out!)

Sample use:

This line of text won't show

This one won't either

Edit: Replaced comment with mycomment since the former conflicts with the semi-popular comment package. This way, if you reuse commented blocks in a project that uses the comment package, nothing will break.

  • If I just want to disable section*{} (and not displaying it, why woudn't \renewcommand{\section}[1]{} work ? Is there a work around? Thanks.
    – CasperYC
    Commented Jan 9, 2020 at 3:49
  • Long story short, starred commands are parsed differently from the normal version. See texfaq.org/FAQ-cmdstar. If you wanted to hide section* blocks, you can do (on separate lines): \usepackage{suffix}, \WithSuffix\newcommand\section*[1]{}
    – ntjess
    Commented Jan 10, 2020 at 18:24
  • 2
    I prefer this solution, as it seems much more readable/verbose to me then the \iffalse ... \fi suggestion.
    – Kim
    Commented Jan 15, 2020 at 9:55
  • This is very easy to use. Thanks
    – creative
    Commented Jun 28, 2020 at 7:11

No, but you can define something close:



\/* This is a test
    and this is another

  • 2
    Can you make \* multiline comments *\ ? Commented Dec 17, 2012 at 7:01
  • 2
    @GarbageCollector You can but then it means changing the catcode of the backtick to make it active and would cause a lot of grief in other areas. Ah! did not see your edit ... changing catcode of slash will give you same headaches.
    – yannisl
    Commented Dec 17, 2012 at 7:03
  • @YiannisLazarides: Of course, this definition cannot be nested. With LuaTeX it is possible to have multiline comments without any catcode jugglery. See Block comments in TeX for an example.
    – Aditya
    Commented Dec 18, 2012 at 8:06
  • It redefines \* and requires a space after the closing delimiter but, \def\*#1*\ {} works I think.
    – Scott H.
    Commented Dec 22, 2012 at 21:05
  • Just a heads-up, this broke \url{} in BibTex for me. (Sadly)
    – domenukk
    Commented Nov 29, 2016 at 16:10

Here's a poor man's version of the answer linked by Aditya above. It doesn't require ConTeXt but it does need to be compiled with LuaTeX. With it you can use C style comments: /*comment*/. A potential downside is that it "works" even in a verbatim environment. It works in all situations I can think of.

This input:

enter image description here

Gives this output:

enter image description here




commenting = false
local gsub = string.gsub

local opencomm = "%/%*(.*)"
local closecomm = "(.-)%*%/"

function comment(s)
    if not commenting then
        s = gsub(s,opencomm,
                commenting = true
                s1 =  gsub(s1,closecomm,function(s2) commenting = false return "" end,1)
                  if commenting then return "" else
                      return comment(s1)
        s = gsub(s,"(.+)",
                s3 =  gsub(s,closecomm,function(s4) commenting = false return "" end,1)
                    if commenting then return "%" else
                        return comment(s3)
    return s

luatexbase.add_to_callback('process_input_buffer', comment, 'comment')


1 /*HIDDEN*/ 2






I think the most straightforward way to do this is to use a TeX editor. TeXnicCenter for instance offers to comment and uncomment marked blocks by ctrl+q and ctrl+w. This simply adds a '%' at the respective lines. This further grays out commented section, which is not the case with scripted solutions.

  • 2
    you can't have inline comments as such for example 2 /* HIDDEN HIDDEN HIDDEN */ 3
    – percusse
    Commented Nov 27, 2013 at 21:18
  • 1
    This is true of course. A scripted version also lets hide/show comments by a simple compile flag, which can be great in drafting or reviewing work. Commented Nov 27, 2013 at 21:46

Short: put \directlua{-- before the block and a single } after the block when compiling with Lua(La)TeX.

Long: this is a "bug" of LuaTeX turned into a feature, or what make programmers happy. Putting a double hyphen in front of a text in Lua means a single-line comment; however, since TeX strips newlines from Lua code, this appears as a single-line chunk to Lua and so all the chunk gets commented.

Not tested, but I think you could alias that as

\newcommand{\multlinecomment}[1]{\directlua{-- #1}}

and then enclose your comment as in

  My multiline
  with Lorem ipsum.

This works for me and I think it is very simple and good enough. Highlight the text that you want to comment using your mouse or keyboard. Once highlighted use Ctrl+t This will comment the selection. You can uncomment the selection by using same steps on commented text.

Hope it helps :)

  • 2
    Am I missing something, or your answer only works for a specific text editor? Commented Aug 7, 2022 at 8:34
  • 1
    In my experience this works TeXstudio and Texmaker. In Overleaf you can use Ctrl+/ as mentioned in one of the questions comments.
    – CH4
    Commented Aug 7, 2022 at 15:43
  • Can I do this easily in vim?
    – Gergely
    Commented Dec 6, 2023 at 13:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .