# An issue in plotting the quantum circuit using latex

Here's the code I'm working on:

!pip install pylatexenc
!pip install pillow

qc = QuantumCircuit(2)
qc.x(0)
qc.cz(0,1)
qc.x(0)
qc.draw('latex')


However there's an error:

FileNotFoundError: [Errno 2] No such file or directory: 'pdflatex': 'pdflatex'


What should I do to make it work? Thanks!!

• Did you try to restart the kernel once the installations were done? Usually in Jupiter Notebook it does the trick :)
– Lena
Jan 14 at 8:53
• @ Thanks for the comment! Yes I did:)
– ZR-
Jan 14 at 20:20

It seems like you forgot to install a $$\LaTeX$$ processor.

To solve the issue, install any $$\LaTeX$$ distribution. Below are the two main ones that can be installed both on Windows and Linux:

If you want to output the circuit in latex format, you can set the output = 'latex' within the draw function of Qiskit.

For instance, suppose I want to plot the following circuit in latex:

           ░       ░
q_0: ──■───░───■───░───■──
┌─┴─┐ ░ ┌─┴─┐ ░ ┌─┴─┐
q_1: ┤ X ├─░─┤ X ├─░─┤ X ├
└───┘ ░ └───┘ ░ └───┘
c: 2/═════════════════════


I can do it as follows:

from qiskit import QuantumCircuit,QuantumRegister
import matplotlib.pyplot as plt
qreg_q = QuantumRegister(2, 'q')
creg_c = ClassicalRegister(2, 'c')
circ = QuantumCircuit(qreg_q, creg_c)
circ.cx(0,1)
circ.barrier(range(2))
circ.cx(0,1)
circ.barrier(range(2))
circ.cx(0,1)
circ.draw( style={'name': 'bw'}, output = 'latex', plot_barriers= True, initial_state = True, scale = 1)


The output would be: You can look into this documentation here for more detail.