0

I'm trying to insert Octave code in a pdf. However, there is a problem with the sign ' (which means transposition in Octave code). However when I copy the code from the generated pdf, the code doesn't run:

\documentclass[a4paper, 12pt]{book}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{mathtools}
\usepackage[utf8]{inputenc}
\usepackage{geometry}
\usepackage{url}
\usepackage{framed}
\usepackage{setspace}
% \usepackage{mathptmx}
\usepackage{multirow}
\usepackage{listings}
\usepackage{xcolor}
\usepackage{framed}
\usepackage{hyperref}
\hypersetup{
colorlinks=true,
linkcolor=blue,
filecolor=magenta,      
urlcolor=cyan,
}

\usepackage{caption}
%\usepackage{calrsfs}
%\DeclareMathAlphabet{\pazocal}{OMS}{zplm}{m}{n}

\begin{document}
\setlength{\parindent}{0cm}
\renewcommand{\baselinestretch}{0.5}
\title{Math notes}
\author{Eric Buffle}
\date{\today}
\maketitle

\tableofcontents{}

\definecolor{shadecolor}{RGB}{240,248,255}
\begin{shaded}
\begin{verbatim}
% BeamStretch
EA=1.0; L=3; F=0.2; N=20; h = L/(N+1); % stepsize
x = (h:h:L)';
f = zeros(size(x)); % f(x) = 0
g = h^2/EA*f ; g(N+1) = g(N+1)/2+h*F/EA;
%% build the triadiagonal , symmetric matrix
di = 2*ones(N+1,1); di(N+1) = 1; % diagonal
up = -ones(N,1); % upper and lower diagonal
u = trisolve(di,up,g); plot ([0;x] ,[0;u])
\end{verbatim}
\end{shaded}

\end{document}

Here is the error message:

parse error:

  syntax error

>>> x = (h:h:L)’;
               ^

error: 'x' undefined near line 1 column 16
error: 'f' undefined near line 1 column 12
error: 'g' undefined near line 1 column 20

I also tried to comment out \usepackage{mathptmx} but the problem persisted I recently posted a similar question but I still couldn't find a solution to the problem

  • For an MWE you shouldn't include all unnecessary package. BTW, you load framed twice. – bmv Nov 10 '18 at 22:52
0

The problem is verbatim handling the single quote. If you load \usepackage{upquote} in the preamble, the ' will be compiled as '. Otherwise, it's compiled as , a different character.

Note that I removed packages and lines that are not strictly neccessary for illustrating the problem.

\documentclass{book}

\usepackage{upquote}

\begin{document}
\begin{verbatim}
% BeamStretch
EA=1.0; L=3; F=0.2; N=20; h = L/(N+1); % stepsize
x = (h:h:L)';
f = zeros(size(x)); % f(x) = 0
g = h^2/EA*f ; g(N+1) = g(N+1)/2+h*F/EA;
%% build the triadiagonal , symmetric matrix
di = 2*ones(N+1,1); di(N+1) = 1; % diagonal
up = -ones(N,1); % upper and lower diagonal
u = trisolve(di,up,g); plot ([0;x] ,[0;u])
\end{verbatim}

\end{document}

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.