I am editing a LaTeX paper with Emacs. Sometimes I want to make a block of texts less obvious (or less important to see). Instead of totally hiding them, they should still be there. Is there an easy way to embed them in something so that it changes color (to grey for instance)?

By the way, besides changing color, are there other ways to easily make a block of texts look less important?

  • 1
    The traditional way to de-emphasize blocks of text in an editor is called text folding (or code folding, for software). stackoverflow.com/questions/1085170/… – Camille Goudeseune May 3 '17 at 17:30
  • 4
    The question wasn't clear, but the answers seem to be focused on changing the color of the output text, not the color of the text in the editor. – Teepeemm May 30 '18 at 13:14

You can use the xcolor package. It provides \textcolor{<color>}{<text>} as well as \color{<color>} to switch the color for some give text or until the end of the group/environment. You can get different shades of gray by using black!x as a color where x is a number from 0 to 100, taken as a percentage.


This is a sample text in black.
\textcolor{blue}{This is a sample text in blue.}

  • 3
    great, \color{<color>} is what i need, thank you very much! – SoftTimur May 1 '11 at 18:13
  • Just one thing, what if my block of code is embedded in \begin{align*} and \end{align*}, which is under math mode. \textcolor... or \color... work on a single word, but not on a block of words... – SoftTimur May 1 '11 at 23:27
  • 12
    No, \textcolor{green}{a couple of words} colors the entire second argument. \color{green} is a declaration, which changes the text color of everything that follows (in that scope, or group as its called in TeX). It is analogous to \textbf versus \bfseries. \color should also work in math mode. But some of the amsmath environments do rather complicated things in order to work (reading the contents several times, for example). But then you could try `{\color{green} \begin{align*} blabla \end{align*} } (note the outer braces). – Villemoes May 2 '11 at 0:40
  • 1
    @SoftTimur: Like Villemoes said, \color should work in mathmode. It would be best if you give an example so we can see where the problem lies. You could edit your question for this. – Martin Scharrer May 2 '11 at 8:39
  • 5
    The following color names are defined: red, green, blue, cyan, magenta, yellow, black, gray, white, darkgray, lightgray, brown, lime, olive, orange, pink, purple, teal, violet. See the package documentation. – Matsmath Oct 7 '18 at 12:16

The following seems simpler:

    This is {\color{red} highlighted}, and this is not.
  • 2
    I think your solution is exactly what @Martin Scharrer is suggesting? – Tom Bombadil Oct 16 '15 at 9:50
  • 1
    No. @Martin Scharrer suggested using the xcolor package, whereas this answer suggests using the hyperref package. – martinweiss Oct 26 '16 at 9:14
  • As a side note: This solution does not change colour of a text in an equation unless xcolor package is used. – Herpes Free Engineer Sep 6 '17 at 14:53
  • 7
    I'm pretty sure \color is not a hyperref command, but that hyperref loads color or xcolor on its own. – Teepeemm May 30 '18 at 13:13

All the above answers are excellent for general purpose

If you want to highlight a syntax for a programming language we can use minted package, it provides excellent colored highlighted text.

To use this package you need to have python installed on your system (you can install python using anaconda package it's great choice) in addition to a package called pygments (to install this package use pip install pygments) it's a python library used to highlight programming language syntax

I'll give a simple example of how to use it

\usemintedstyle{vim} %note here you can use different highlighting
                      %styles see the final note below


import matplotlib.pyplot as plt
import numpy as np

t=[i for i in np.arange(-5,5,1/200)]

for i in range(N):
    if (abs(t[i])!=(T/2*alpha)):
            (1- 4*alpha**2 *(t[i])**2 /(T**2))))


This code will produce the following This the output of the above code

Note you need to enable " -shell-escape " option with either LaTeX or pdfLaTeX

latex -shell-escape foo.tex


pdflatex -shell-escape foo.tex

If you want to get different highlights, on the command line use

pygmentize -L styles

You'll get different styles of highlighting

CHEERS, Hizzani


Use the package


and right after that write this line given below :


Now wherever you want to highlight some text use \myRed{}.

When you compile, you will get text in \myRed in red color.

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.