6

I would like to create a block around javascript code in latex.

I use minted package for format highlighting.

Here is my example code:

\documentclass[]{article}
\usepackage{minted}

%opening

\begin{document}

\begin{listing}[H]
\begin{minted}{js}
var http = require("http");
    http.createServer(function(request, response) {
        response.writeHead(200, {"Content-Type": "text/plain"});
        response.end();
    }).listen(8080);
\end{minted}
\caption{Example of a listing.}
\end{listing}

\end{document}

And I get the output as this

I would like to create a block around the code. Or a table embedding the code.

Any help is really appreciated.

And one more thing, whenever I run the above example on TexmakerX, I get an error Package

minted Error: You must invoke LaTeX with the -shell-escape flag

But when I run it in the cmd, using

pdflatex -shell-escape filename

it seems to work fine.

How can I make it run in Texmakerx?

4

Do you want to achieve something like this?

enter image description here

Do you mean you want to put a frame around your code? You have to use the frame option. You can choose from the values none (the default), leftline, topline, bottomline, lines, single.

\documentclass[]{article}
\usepackage{minted}

%opening

\begin{document}

\begin{listing}[H]
\begin{minted}[frame=single]{js}
var http = require("http");
    http.createServer(function(request, response) {
        response.writeHead(200, {"Content-Type": "text/plain"});
        response.end();
    }).listen(8080);
\end{minted}
\caption{Example of a listing.}
\end{listing}

\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.