4

I want to copy/paste some text in my latex file as is. I use \begin{verbatim} ... \end{verbatim}

The problem is when I copy long text like the following, the text is rendered in one line which exceeds the page. Is there any option to wrap the long text automatically?

the sample:

curl -v -s -X POST $OS_AUTH_URL/auth/tokens?nocatalog -H "Content-Type: application/json" -d '{ "auth": { "identity": { "methods": ["password"],"password": {"user": {"domain": {"name": "'"$OS_USER_DOMAIN_NAME"'"},"name": "'"$OS_USERNAME"'", "password": "'"$OS_PASSWORD"'"} } }, "scope": { "project": { "domain": { "name": "Default" }, "name": "'"$OS_PROJECT_NAME"'" } } }}' | python -m json.tool

1 Answer 1

3

A simple method is with fancyvrb and fvextra:

\documentclass{article}
\usepackage{fancyvrb,fvextra}

\usepackage{showframe} % just for the example

\begin{document}

\begin{Verbatim}[breaklines]
curl -v -s -X POST $OS_AUTH_URL/auth/tokens?nocatalog -H "Content-Type: application/json" -d '{ "auth": { "identity": { "methods": ["password"],"password": {"user": {"domain": {"name": "'"$OS_USER_DOMAIN_NAME"'"},"name": "'"$OS_USERNAME"'", "password": "'"$OS_PASSWORD"'"} } }, "scope": { "project": { "domain": { "name": "Default" }, "name": "'"$OS_PROJECT_NAME"'" } } }}' | python -m json.tool
\end{Verbatim}

\end{document}

enter image description here

The example uses showframe just for being sure the breaks respect the text width.

For also having syntax highlighting you can use minted:

\documentclass{article}
\usepackage{minted}

\usepackage{showframe} % just for the example

\begin{document}

\begin{minted}[breaklines]{bash}
curl -v -s -X POST $OS_AUTH_URL/auth/tokens?nocatalog -H "Content-Type: application/json" -d '{ "auth": { "identity": { "methods": ["password"],"password": {"user": {"domain": {"name": "'"$OS_USER_DOMAIN_NAME"'"},"name": "'"$OS_USERNAME"'", "password": "'"$OS_PASSWORD"'"} } }, "scope": { "project": { "domain": { "name": "Default" }, "name": "'"$OS_PROJECT_NAME"'" } } }}' | python -m json.tool
\end{minted}

\end{document}

enter image description here

In both cases, the character after the break can be customized.

3
  • Great. Great. Thanks! Is there a way to make it default for Verbatim or minted?
    – Reza
    Sep 29, 2019 at 22:11
  • @Reza For fancyvrb use \fvset{breaklines}, for minted it's \setminted{breaklines} (in the document preamble)
    – egreg
    Sep 29, 2019 at 22:15
  • You are awesome!
    – Reza
    Sep 29, 2019 at 22:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .