# Adding programing code on LaTeX

I need to put some code from Linux's configuration files and some JavaScript in a document. I have tried to use \texttt, it worked for some Linux's basic commands like sudo apt-get install XYZ, but the code that I need to insert have # for comments and $for variables. Is there some special tag for this? Here some example of the code that I need to paste in document: JavaScript: var api = new ParseServer({ databaseURI: databaseUri || 'mongodb://localhost:27017/dev', // Endereço do banco de dados mongodb com a porta padrão cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js', appId: process.env.APP_ID || 'myAppId', //Identificação da aplicação masterKey: process.env.MASTER_KEY || '', //Add your master key here$ //Chave secreta para o aplicativo se conectar ao servidor
serverURL: process.env.SERVER_URL || 'http://localhost:1337/parse',$//URL que vai estar disponível após o parse-server iniciar liveQuery: { classNames: ["Posts", "Comments"] // List of classes to support f$
}

Configuration File:

# HTTPS — proxy all requests to the Node app
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name app.example.com;
}

I'm using ShareLatex. I don't know if it can make any difference on this part.

• I am not sure that I understand what you are trying to do but if you just want to insert code into a latex document then I recommend using the listings package. The documentation is very readable and there are multiple examples on TeX.SX. Another alternative is minted. – Andrew May 22 '17 at 1:40

Use the listings package. Unfortunately, there are no syntax highlighting patterns for Javascript in listings.

Because most of the lines in your code are too wide for the page you should apply my solution for lstlisting line wrapping.

\documentclass{article}

\usepackage{listings}
\usepackage{xcolor}
\lstset{
basicstyle=\ttfamily,
columns=fullflexible,
breaklines=true,
postbreak=\raisebox{0ex}[0ex][0ex]{\color{red}$\hookrightarrow$\space}
}

\begin{document}

\begin{lstlisting}[frame=single]
var api = new ParseServer({
databaseURI: databaseUri || 'mongodb://localhost:27017/dev', // Endereço do banco de dados mongodb com a porta padrão
cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
appId: process.env.APP_ID || 'myAppId', //Identificação da aplicação
masterKey: process.env.MASTER_KEY || '', //Add your master key here$//Chave secreta para o aplicativo se conectar ao servidor serverURL: process.env.SERVER_URL || 'http://localhost:1337/parse',$
//URL que vai estar disponível após o parse-server iniciar
liveQuery: {
classNames: ["Posts", "Comments"] // List of classes to support f\$
}
\end{lstlisting}

\begin{lstlisting}[frame=single]
# HTTPS — proxy all requests to the Node app
server {