-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[feature request] autolinebreak for fenced code under skylighting #4302
Comments
I don't think this can be implemented in skylighting itself, because skylighting has no way of knowing how much space each token takes and hence when the end of the line is reached. If there's some latex magic that can cause auto wrapping inside a custom verbatim environment defined using fancyvrb, then we could use that. |
On the LaTeX side I believe the package fvextra (github) could be a nice candidate doing all the tedious work by directly talking to - or rather through - I had a short look at For the solution only two tiny edits to the tex code are needed: %% add
\usepackage{fvextra}
...
%% add the breaklines option like so
\begin{Highlighting}[breaklines,numbers=left,,]
... Please feel free to close this issue as you may find appropriate. @jgm Separately, John, two additional observations:
Example:
gets translated to
HTH. |
These edits in the preamble would work, too: \usepackage{fvextra}
\DefineVerbatimEnvironment{Highlighting}{Verbatim}{breaklines,commandchars=\\\{\}} |
How about prepending to % single line spacing for code
\usepackage{etoolbox}
\BeforeBeginEnvironment{verbatim}{\def\baselinestretch{1}} |
BTW - my suggestion would amend an already existing 'custom' environment created by the current version of Or am I missing anything here, since I am lightyears away from being a LaTeX expert? |
Sorry, now I see expressed myself poorly. That was just an example of how it is possible to prepend commands to the existing
... but pandoc already does it, so your suggestion to amend looks good to me. |
I also think @jannick0 's suggestion perfectly fits the bill. I took the liberty to mention it as an answer to a question asked on StackExchange, cf. https://tex.stackexchange.com/a/412316/34551 |
Writing a technical report with code blocks or long string is really a nightmare. Even with fvextra and the |
If you don't care about where they split, you can use a lua filter to add line breaks automatically. |
I'm using markdown to PDF conversion through a LaTeX template made by someone else. I'll rather avoid to have to tweak it. |
A filter doesn't require changes to tempate. |
@jgm I imagined it was something you put in your LaTeX document, but I looked for it an I saw it was an additional option to pass to pandoc. This make an extra file and I know anything about lua lang. |
Pandoc tries to use only packages which are shipped with texlive-latex-recommended in Debian-based distros. The suggested package My personal suggestion would be to use minted, e.g. via the minted Lua filter. |
My workaround to handle the code blocks without a language is setting the language to text via a lua filter function CodeBlock(el)
if #el.classes == 0 then
el.classes[1] = 'text'
end
return el
end
return {{CodeBlock = CodeBlock}} Save the file and use it via the pandoc command line option: |
Perhaps I took a hammer to an egg here, but I was having a hard time line breaking code of regex so I needed break-anywhere. I ended up with this: ---
format:
html:
code-fold: true
pdf:
header-includes:
- "\\usepackage{fvextra}"
- "\\DefineVerbatimEnvironment{Highlighting}{Verbatim}{commandchars=\\\\\\{\\}, breaklines, breaknonspaceingroup, breakanywhere}"
- "\\fvset{breaklines}"
- "\\fvset{breaknonspaceingroup}"
- "\\fvset{breakanywhere}"
latex-auto-install: true
--- |
Pandoc 2.0.6 / skylighting 0.5.0.1:
It appears that for fenced code blocks with long lines there is no autolinebreak feature (for style pygments, at least).
Example:
pandoc -f markdown -t latex -o long-code-line.pdf long-code-line.md
NB: Options of the LaTeX listings package:
Apologies if there is a trivial solution to this issue making this feature request obsolete.
The text was updated successfully, but these errors were encountered: