Comments (13)
I'm glad too see some progress as minted is the best syntax highlighter for source code in LaTeX, but automatic line breaks are really essential to me.
from minted.
Hi,
for the moment you can use TeX.SX: Box around minted environment
Please note that the break only occurs at spaces.
Best regards
Marco
from minted.
Thanks, but it would be best that it's supported by minted self like listings. And there's more. How about breaking between pages? The way you showed is only about line break.
—
Sent from Mailbox for iPhone
On Tue, May 21, 2013 at 1:00 PM, Marco Daniel [email protected]
wrote:
Hi,
for the moment you can use TeX.SX: Box around minted environment
Please note that the break only occurs at spaces.
Best regardsMarco
Reply to this email directly or view it on GitHub:
#1 (comment)
from minted.
Hi,
page breaks are possible as well. There are no limitations.
Best regards
Marco
from minted.
In this case, I would try myself. But still it would be awesome that these features are supported natively.
—
Sent from Mailbox for iPhone
On Tue, May 21, 2013 at 4:21 PM, Marco Daniel [email protected]
wrote:
Hi,
page breaks are possible as well. There are no limitations.
Best regardsMarco
Reply to this email directly or view it on GitHub:
#1 (comment)
from minted.
I hope to support both features sometime soon, but it may take a little while. The current focus is on getting out a new release that closes a lot of the old bugs on Google Code, and on transferring some features between minted
and pythontex
.
from minted.
The old issue on google code referenced a patch to pygments that was necessary to support this feature. A rebased version of that patch has been merged -- does that impact the difficulty of this issue?
from minted.
@sprocter Now that the patch has been merged, manual linebreaks as described in that issue should be possible. This will still require some trickery on the fancyvrb
side of things. Basically, there will need to be a macro (something like \manualbreak
) that will disable line numbering (and line incrementing) for the following line, and only the following line. I will try to investigate those possibilities (and other things this will make possible) later this summer.
Unfortunately, the patch may not do much for automatic line breaking. It might be possible to combine escaping to LaTeX with a command-line tool that formats code, so that whenever the tool breaks a line, it also automatically adds a \manualbreak
. But that is problematic if their are any LaTeX escapes created by the user, because their width can't be judged by a formatting tool, only by LaTeX itself. So automatic line breaking probably still needs a solution on the LaTeX side, though this may help in some cases.
from minted.
I've added automatic line breaking. When auto line breaking is on, manual breaking is also possible by using escapeinside
to escape to LaTeX, and then using \\
to break the line. Thanks to @marcodaniel for inspiring the general approach with the code he referenced.
Let me know if you find bugs, or have suggestions regarding the default settings when breaklines=true
.
Brief overview of line breaking
breaklines
turns on automatic line breaking.breakindent
sets the indentation of continuation lines.breakautoindent
automatically indents continuation lines to the same level as the first line.breaksymbol
sets the symbol that indicates continuation lines.breaksymbolindent
sets the extra indentation that is added to continuation lines to make room for the symbol.breaksymbolsep
sets the separation from the edge of the symbol to the edge of the adjacent code.
Limitations of the current approach
- Only automatically breaks lines at space characters. Probably not much can be done about that, at least not without hacking Pygment's LaTeX formatter or at least its style sheet.
- Pygments styles like
colorful
put a colored background behind strings. These can't break. (They use\colorbox
internally, and I haven't been able to find a satisfactory replacement that allows breaks.) - Breaks don't work when
showspaces=true
(there aren't any actual spaces in that case). - Breaks interfere with the
frame
option (butframed
,mdframed
, ortcolorbox
give better results anyway).
from minted.
Basic automatic line breaking support is now complete, so I am closing this. Automatic breaks now cooperate with fancyvrb
's frame option. It is now possible to put line continuation symbols in both the left and right margins. The breakbytoken
option provides better control of where breaks occur.
I'm currently finalizing the 2.0 release. Future releases will likely bring enhancements to line breaking.
from minted.
I'm sorry for pushing this thread, but since automatic page break is one of the most needed things I'd really like to see an (at least) workaround to enable mdframed
by option.
I saw that you mentioned
\BeforeBeginEnvironment{minted}{\begin{mdframed}} \AfterEndEnvironment{minted}{\end{mdframed}}
would help to automate the process of pagebreaking and I even found out that
\begin{mdframed}[leftmargin=0pt,innerleftmargin=3pt,innertopmargin=3pt,rightmargin=0pt,innerrightmargin=3pt,innerbottommargin=3pt,topline=false, bottomline=false, leftline=false, rightline=false, backgroundcolor=XXX]
will be visually the same as standard minted
AND enable flawless pagebreaking, but I noticed it will come to an endless loop if you want to set background color using mdframed
and minted
together.
So the solution is to only set the background color in mdframed
option as I made where XXX
is the color, but I wanted to know how the color name could be passed automatically to mdframed
from minted
.
To be more clear, I want to have something like:
\BeforeBeginEnvironment{minted}{\begin{mdframed}[...,backgroundcolor=#1]}
If you have an answer for this I would be really glad, and also if you could maybe integrate it at least with in option like breakpages
.
That would be a huge step for minted
.
from minted.
@unidesign In the future, it might be better to open a new issue for something like this, since this seems to be more of a feature request or question about mdframed
compatibility, rather than a direct continuation of the existing (closed) issue.
I think you can get most of what you want using something like the following example. This doesn't tie everything directly into minted
, but the typing required is about the same. I am interested in adding integration with framing packages in the future, but since there are several popular packages (framed
, mdframed
, tcolorbox
, etc.), anything that I add will be very general, something along the lines of, say, \begin{minted}[mdfsetup={...}]{<lang>}
.
\documentclass{article}
\usepackage{xcolor}
\usepackage{mdframed}
\usepackage{minted}
\BeforeBeginEnvironment{minted}{%
\begin{mdframed}[leftmargin=0pt,innerleftmargin=3pt,innertopmargin=3pt,
rightmargin=0pt,innerrightmargin=3pt,innerbottommargin=3pt,topline=false,
bottomline=false, leftline=false, rightline=false]}
\AfterEndEnvironment{minted}{\end{mdframed}}
\begin{document}
\mdfsetup{backgroundcolor=green}
\begin{minted}{python}
def f(x):
return x**2
\end{minted}
\mdfsetup{backgroundcolor=yellow}
\begin{minted}{python}
def f(x):
return x**2
\end{minted}
\end{document}
from minted.
@gpoore Thank you very much, this works good for me, especially because I only want one background color in general so I can set up the whole block in preamble.
I noticed no disadvantages when using mdframed
with minted
(except that you can not pass color every time without extra command).
PS: I also thought about creating a new topic but googling this yields to this page and also the point about page breaking wasn't answered here.
If you edit the documentation next time maybe you could add this small workaround for pagebreaking I googled more than two hours but there was not one good solution. Also the code on stackexchange
doesn't work with color and won't give visually the same result as minted
.
from minted.
Related Issues (20)
- `newmintedfile` env* to specify additional options HOT 9
- [bug] `gobble` results in malformed formatting, `autogobble` works HOT 5
- [show-&-tell] ad-hoc adoptations from a different style to another one. HOT 1
- [feature] Support for PDDL programming language HOT 2
- [bug][compatibility] `Verbatim` environment generated by `minted` with `mathescape` broken with `babel`'s `magyar.ldf` (Hungarian 🇭🇺 language) HOT 1
- JSX highlighting is not working in overleaf HOT 1
- breaksymbolleft flush with line numbers HOT 2
- Write env content to file HOT 2
- Failed Compilation with MikTeX on windows HOT 19
- Overfull hbox with `mintinline` and `breakanywhere` in enumerate environment HOT 1
- Escapeinside content is misplaced in pygtex file for nodejsrepl type HOT 7
- Because of changes in one of the most popular Python installer on Mac, doc needs an improvement (`pip3 install Pygments` doesn't work anymore) HOT 1
- file extension `lol' cannot be used twice HOT 3
- autogobble option not working for me HOT 12
- Can not compile via latexmk in Windows HOT 5
- Missing Pygments output; \inputminted... HOT 2
- [Feature request] named code segments HOT 1
- Get full timestamp in XeTeX through \creationdate HOT 1
- Error : Missing Pygments Output HOT 9
- Feature request - mintinline max. depth and height HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from minted.