Fonts in LaTeX

Associate
Joined
6 Nov 2006
Posts
722
Location
Devon
Apologies if this is a stupid question but I have only a very limited knowledge of LaTeX.
I am trying to typeset a piece of work in LaTeX and I need to add in some chunks of Matlab code. Is there a command for adding code similar to the HTML <code> tag to make it noticeably different from ordinary text?

Thanks
 
That looks like just what I need, but when I try it I put the line

Code:
\lstinputlisting[language=Matlab]{pend.m}

where pend.m is the name of my Matlab function, when I press typeset i get the error

Code:
! Undefined control sequence.
l.33 \lstinputlisting
                     [language=Matlab]{pend.m}

I have just copied and pasted from the link changing Python to Matlab and the file name to my file name.
What am I missing?
 
Last edited:
edit: Looks like I've got it working now although I have another question - how do I line up = signs in equations when I have 2 or more equations on top if each other?

Thanks
 
Last edited:
edit: Looks like I've got it working now although I have another question - how do I line up = signs in equations when I have 2 or more equations on top if each other?

Thanks

Normally you prefix them with an &, so if you have &= on two different lines then they align. I think this might depend on which package you're using for equations though, worth a shot still.
 
IIRC it was standard practice at my old uni to just use \verbatim{ code here } not particularly nice if you have some very long lines of code though. A friend passed me a really cool perl script a while back that generated really nice coloured latex code for code and it sorted the "past the end of the page" problem. Will try and dig it out.
 
Normally you prefix them with an &, so if you have &= on two different lines then they align. I think this might depend on which package you're using for equations though, worth a shot still.

They need to be in an align (or align*) environment, too; e.g.

Code:
\begin{align}
y &= f(x)\\
z &= g(x)
\end{align}

This works with any symbol, so you could just as well use \approx or \sim instead of an equals sign.

(Assuming you're using the amsmath package for equation typesetting.)
 
Last edited:
They need to be in an align (or align*) environment, too; e.g.

Code:
\begin{align}
y &= f(x)\\
z &= g(x)
\end{align}

This works with any symbol, so you could just as well use \approx or \sim instead of an equals sign.

(Assuming you're using the amsmath package for equation typesetting.)

I tried
Code:
\begin{align}
\begin{equation}
\frac{dy_1}{dt} = y_2
\end{equation}

\begin{equation}
\frac{dy_2}{dt} = -\sin(y_1)-2 \alpha y_2+F\cos(nt)
\end{equation}
end{align}
but I just get

! LaTeX Error: Environment align undefined.

do I need the amsmath package for the align environment align to work?
 
Also, you don't need to use equation environments within an align environment, but don't forget the line separators (\\).
 
Last edited:
It works:D

Thanks Guys

Just one last question (for now) - When I typeset it I get massive white gaps at the tops and bottoms of the pages. Is there an easy way to get rid of this?
 
This also reduces the margins at the sides, though (which are that size for a reason).

I think, well more I hope that you can see recommending fullpage for someone who clearly is a beginner to latex is much better than recommending him to try and configure margins himself, which, from experience is a nightmare:p
 
Just another quick question - how can I add a caption to images? I have tried using the figure command but although I can then add a caption it also adds figure numbers which I do not really want, I just need the caption. Can I remove the figure numbers or is there an easier way to add a caption?

Thanks
 
Back
Top Bottom