TeX - LaTeX Asked on November 1, 2021
Edit: thank you for commenting. I’ve edited the question to use lstnewenvironment
but it keeps giving the same error. I will keep the question here while I go read the lstlistings
manual.
The following code works for me when used inside the document:
begin{adjustwidth*}{0pt}{-5cm}
begin{lstlisting}
function test() { return (void *) test_func(a, b, 3); }
end{lstlisting}
end{adjustwidth*}
But when I want to create a custom environment for it, Overleaf gives me the error
job aborted, no legal end found.
MWE:
documentclass{article}
usepackage[right=10cm]{geometry} % Create a large right margin
usepackage{listings}
usepackage{changepage}
% Create a new environment for code samples that can extend into the outer margin.
lstnewenvironment{config}{%
begin{adjustwidth*}{0pt}{-5cm}
}{%
end{adjustwidth*}
}
begin{document}
begin{config}
function test() { return (void *) test_func(a, b, 3); } asdfasdfa asdf
end{config}
end{document}
Apparently, changepage
and listings
fight each other. However, you don't need changepage
for this application.
documentclass{article}
usepackage[right=10cm]{geometry} % Create a large right margin
usepackage{listings}
usepackage{lipsum}
% Create a new environment for code samples that can extend into the outer margin.
lstnewenvironment{config}[1][]{lstset{xrightmargin=-5cm,#1}}{}
lstset{basicstyle=ttfamily,columns=fullflexible} % so my eyes don't bleed
begin{document}
lipsum[1][1-4]
begin{config}
function test() { return (void *) test_func(a, b, 3); } asdfasdfa asdf
end{config}
end{document}
You can add listings
options to config
in the usual way, by calling `begin{config}[]
Answered by egreg on November 1, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP