# Code using verbatim doesn't work when copied back in a text editor

I'm trying to use verbatim to copy the implementation of an algorithm written in octave. For this I introduced the following lines in latex

\begin{verbatim}
F = @(z) [z(1) + 2*z(2) - 2; 2*z(2)*z(3)^2 - 2/3; 2*z(2)*z(3)^4 - 2/5];
\end{verbatim}


That generates in return a piece of code on a pdf document. However when I copy back the code from the generated pdf to a text editor, the code doesn't work because the exponential sign ^ copied into the text editor differs from the original code written in the text editor. The proof that this is the problem is that when I erase and rewrite the ^ sign from the copied chunk of code, the code works.

How is it possible to fix the problem? Because the goal of function like verbatim is to have ready to use code when copying from a latex document and not having to extra edit it when before running it.

EDIT

I generated the following new .tex file and it works.

\documentclass[a4paper, 12pt]{book}
\begin{document}

\chapter{Questions}
\begin{verbatim}
F = @(z) [z(1) + 2*z(2) - 2; 2*z(2)*z(3)^2 - 2/3; 2*z(2)*z(3)^4 - 2/5];
\end{verbatim}
\end{document}


How come doesn't it work in my principal .tex file? Is it possible that it comes from all the packages that I'm using?

\documentclass[a4paper, 12pt]{book}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{mathtools}
\usepackage[utf8]{inputenc}
\usepackage{geometry}
\usepackage{url}
\usepackage{framed}
\usepackage{setspace}
\usepackage{times}
\usepackage{multirow}
\usepackage{listings}

\begin{document}
\setlength{\parindent}{0cm}
\renewcommand{\baselinestretch}{0.5}

• Can you make a minimal working example (MWE)? Maybe the listings package could be an alternative Nov 4 '18 at 11:27
• Thank you for your comment @samcarter. I edited the question after your comment. I already tried listings previously and it made the problem even worse: on top of the problem with exponential ^ sign, also present in listings, there was the same problem with multiplication *sign which wasn't recognized on the text editor
– ecjb
Nov 4 '18 at 11:43
• Can you make a MWE that reproduces the problem? Nov 4 '18 at 11:45

If you replace the times package (which is obsolete) by the mathptmx package, your problem should be resolved.