How to change color for a block of texts?

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.

\usepackage{xcolor}
\begin{document}

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

\end{document}

The following seems simpler:

\documentclass{amsproc}
\usepackage[colorlinks]{hyperref}
\begin{document}
    This is {\color{red} highlighted}, and this is not.
\end{document}

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

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

\begin{document}

\begin{minted}{python}
import matplotlib.pyplot as plt
import numpy as np

T=1
delta_T=T/200
alpha=0.5
fc=40/T
A_m=1
t=[i for i in np.arange(-5,5,1/200)]
t_arr=np.array(t)
N=len(t)

g_T=[]
for i in range(N):
    if (abs(t[i])!=(T/2*alpha)):
        g_T.append(np.sinc(t[i])*(np.cos(np.pi*alpha*t[i]/T)/
            (1- 4*alpha**2 *(t[i])**2 /(T**2))))
    else:
        g_T.append(0)
\end{minted}

\end{document}

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

or

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

Tags:

Color