# How to typeset verbatim code?

63 views

How can I typeset the following MATLAB code verbatim?

% A MATLAB version of the NAG subroutine C02AFZ
% for computing the zeros of polynomials using
ndeg = length(f) - 1; %degree of polynomial
n = ndeg; N = n+1;
ihalf = 0; ispir=0; iter = 0;
cauchy = 0; %Region containing smallest

edited

Please always provide a minimal (La)TeX code whenever you ask any questions.

You can use the verbatim environment to typeset any verbatim code. So

\documentclass{article}
\usepackage{xepersian}
\settextfont{Yas}
\begin{document}
\begin{LTR}
\begin{verbatim}
% A MATLAB version of the NAG subroutine C02AFZ
% for computing the zeros of polynomials using
ndeg = length(f) - 1; %degree of polynomial
n = ndeg; N = n+1;
ihalf = 0; ispir=0; iter = 0;
cauchy = 0; %Region containing smallest
\end{verbatim}
\end{LTR}
\end{document}


will do. The extra LTR environment is necessary to typeset the verbatim code left to right.

What's the difference between using the LTR environment here instead of the latin environment?
In general, the latin environment is the same as the LTR environment with few exceptions
• Counters alph and Alph gives you lowercase and uppercase English Alphabets, respectively;
• The script is latin;
• The font is latin.
In this special case, it does not make any difference; you can either use the LTR or the latin environment. However, using the latin environment seems to be redundant as the verbatim environment font is typewriter.