gpoore / fvextra Goto Github PK
View Code? Open in Web Editor NEWextensions for the LaTeX fancyvrb package, including a better \Verb, automatic line breaking, and improved math mode
extensions for the LaTeX fancyvrb package, including a better \Verb, automatic line breaking, and improved math mode
Due to this issue, the docs need to be updated.
A fix may be possible, but will likely be complicated since it will have to dig into the details of the inputenc
implementation of UTF-8 with active bytes in the 128-255 range.
The purpose of this feature is to let odd- and even lines have different highlight colors. I have committed a demo implementation to my forked repo. Only sty file is changed in that commit.
Some Explanations
highlightcolor
can be used as highlightcolor = SingleColor | {<OddLineColor>, <EvenLineColor>}
.highlightlinenumbercolor
changes the highlight color of line number, and this option can be used the same as highlightcolor
.\arabic{FancyVerbLine}
) is hard, a new option linenumberwidth=<dimen>
is defined.breaklines=true
, the total heigh of a line is not determined until \FV@SaveLineBox
. Therefore \FV@LeftListNumber
(with its background) is typeset after \FancyVerbFormatLine
.Shortcut:
\def\FV@LineNumberBackground{}
is a compromise since \def\FV@LineNumberBackground\@empty
and \def\FV@LineNumberBackground\relax
both raise error. I guess it is a problem of order of macro expanding.\pickTwo
macro may have nicer implementation.I am not fully understood about packages fancyvrb
and fvextra
, so any suggestions are helpful. And, more test is needed of course.
Hi,
many thanks for this package. The manual states that the macro \SaveVerb
also has a starred version:
5.2 \SaveVerb
\SaveVerb*[<options>]{<name>} <delim char or {> <text> <delim char or }>
\SaveVerb
is reimplemented so that it is equivalent to the reimplemented
\Verb
. Like the new\Verb
, it acceptstext
delimited by a pair of curly braces
{...}
.
The starred version for \Verb
means a shortcut for showspaces
, but does this make sense when read in and save a portion of text? Or am I missing something?
\usepackage{fvextra}
\renewcommand{\VERB}{\Verb[commandchars=\\\{\},breaklines,breaksymbolleft={\tiny\ensuremath{\hookrightarrow}}]}
\DefineVerbatimEnvironment{Highlighting}{Verbatim}{commandchars=\\\{\},breaklines,breaksymbolleft={\tiny\ensuremath{\hookrightarrow}}}
The hookrightarrow symbol is added both in \VERB
command and in Highlighting
environment.
It only works in the environment, command version breaks lines but does not insert the symbol.
Discovered when extending my TeX-SX answer https://tex.stackexchange.com/a/549941 to cover \mintinline
, in response to a user comment.
For <code>
passed to codes
or codes*
option, when typesetting verbatim input,
fancyvrb |
fvextra |
|
---|---|---|
displayed like Verbatim env |
uses <code> |
uses <code> |
inline like \Verb |
uses <code> |
ignores <code> |
\documentclass{article}
\usepackage{fancyvrb}
\begin{document}
With \texttt{fancyvrb}
\begin{Verbatim}[codes=\fvset{showspaces}]
displayed a = b + c
\end{Verbatim}
\Verb[codes=\fvset{showspaces}]|inline a = b + c|
\end{document}
\documentclass{article}
\usepackage{fvextra}
\begin{document}
With \texttt{fvextra}
\begin{Verbatim}[codes=\fvset{showspaces}]
displayed a = b + c
\end{Verbatim}
\Verb[codes=\fvset{showspaces}]|inline a = b + c|
\end{document}
I understand codes
is designed to accept catcode changes hence above is wrong usage and formatcom
and formatcom*
are better choices, and the latter group options indeed work for \Verb
and VerbEnv
with fvextra
loaded.
But since this is an inconsistency between fvextra
and fancyvrb
, maybe at least it need to be documented.
If you have very long words in an markdown codeblock and try to convert it to an PDF using pandoc, the breaklines and breakanywhere directives do not work as expected.
I tried to report this issue in the pandoc issue tracker before (jgm/pandoc#6069). It was pointed out that it is an fvextra issue.
Input:
Output:
Expected Output:
The long URL should be broken in between, and have an indicator showing that it's the same line. The line break should respect the page margin.
Pandoc Version:
pandoc 2.9.1.1
Compiled with pandoc-types 1.20, texmath 0.12, skylighting 0.8.3
Default user data directory: C:\Users\Tobias Schwarz\AppData\Roaming\pandoc
Copyright (C) 2006-2019 John MacFarlane
Web: https://pandoc.org
This is free software; see the source for copying conditions.
There is no warranty, not even for merchantability or fitness
for a particular purpose.
Steps to reproduce:
Use the attached pandoc-test.txt with the following commandline:
pandoc -f markdown -o pandoc-test.pdf pandoc-test.txt
Best regards
Tobias
\documentclass[]{ctexart}
\usepackage{fvextra}
\begin{document}
\begin{Verbatim}[breaklines, breakanywhere]
line 1
very_loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_word_longger_thon_a_page
line 2
line 3
\end{Verbatim}
\end{document}
Hi, how are you, first of all, thank you very much for the great work with the fvextra
package. I have an idea in mind that maybe you could add to this great package.
In several of the packages created by you use a macro to save content using \scantokens
, in some forum responses like in:
(https://tex.stackexchange.com/questions/328517/understanding-makeatletter-with-minted-minipage-colorboxes)
(https://tex.stackexchange.com/questions/373647/collect-contents-of-an-environment-that-contains-verbatim-content)
it avoids using auxiliary files or boxes to store \verbatim
content in an environment.
As the environ
package does not support verbatim (inline/env) content (you can use \cprotect
, but it fails with [opt]
) .
You could add a functionality like that of the environ
package but that supports verbatim using \ scantokes, something like
\NewEnvironv{name}[N. args][opt. arg]{macro}[final code]
whit \BODYv
by default?
(v
for verbatimized)
Greetings.
PS: Sorry if my English is not very clear, it's not my native language :)
I was surprised to find loading package minted
would change quote display in a verbatim
(not Verbatim
) environment.
My current understanding is that loading minted
would also load fvextra
and upquote
in turn. It is the upquote
package that modifies environment verbatim
.
I don't think the fvextra
package was made to hack verbatim
. I would appreciate if you provide a package option curlyquotes
such that if set then package upquote
is not loaded at all, and so my verbatim
environments are left untouched.
I have 2 temporary solutions to the problem at hand:
I can either use \begin{verbatim}[curlyquotes]
for each verbatim
environment, or call \fvset{curlyquotes=true}
right after loading minted
or fvextra
. You see, neither is documented and I don't even know if they truly work.
To be precise, \fvset
is documented but for Verbatim
not verbatim
.
\edef\FV@commachar{\string,}
\newcommand{\FV@EscChars}{%
\let\#\FV@hashchar
\let\%\@percentchar
\let\{\@charlb
\let\}\@charrb
\let\$\FV@dollarchar
\let\&\FV@ampchar
\let\_\FV@underscorechar
\let\\\@backslashchar
\let~\FV@tildechar
\let\~\FV@tildechar
\let\[\FV@leftsquarebracket
\let\]\FV@rightsquarebracket
\let\,\FV@commachar
}
Line breaking needs to be customized for LuaTeX by setting \automatichyphenmode=2
. Otherwise, a hyphen is automatically converted to a discretionary and thus there may be undesired line break locations.
See gpoore/minted#263 for example. See LuaTeX manual around page 71 for details.
To improve the usability of the feature suggested in #8 , I am re-thinking the options and the beneath logic of the general highlight feature. The re-designed options
highlight-lines
to choose which highlight mode is usedhighlight-line-numbers
to toggle whether highlight the line number partThis is only a design- and pseudo-level discussion, therefore the actual package code in my forked repo is not modified yet.
Options
- highlight-lines = <empty> | <selected lines>
- default value <empty>
- highlight-color = <color>
- default value `LightCyan`
Logic
if (hightlight-lines is <empty>) then
normal
else
highlight <selected lines> in <color>
fi
Options
(Modified)
- highlight-lines = <empty> | <selected lines> | <alternate>
- default value <empty>
- highlight-color = <line color> | {<line color>, <line number color>}
- default value `{LightCyan, LightYellow}`
(Added)
- highlight-line-numbers = <boolean value>
- default value `false`
- highlight-odd-line-color = <odd line color>
| {<odd line color>, <odd line number color>}
- default value `{LightCyan, LightYellow}`
- highlight-even-line-color = <even line color>
| {<even line color>, <even line number color>}
- default value `{LightCyan!60, LightYellow!60}`
Logic
if (highlight-lines is <empty>) then
normal
else if (highlight-lines is <selected lines>) then
if (line-number is typeset && highlight-line-numbers is `true`) then
highlight <selected lines> in <line color>,
with line numbers in <line-number-color>
else
highlight line of <selected lines> in <line color>
fi
else // (highlight-lines is <alternate>)
if (line-number is typeset && highlight-line-numbers is `true`) then
highlight odd lines in <odd-line-color>, even lines in <even-line-color>,
with line numbers in corresponding colors
else
highlight odd lines in <odd-line-color>, even lines in <even-line-color>
fi
fi
Notes
alternate rows
is more popular than zebra effect
, the following one is used in issue minted/#211.linenumbersep
, but its function is off-topic to this issue, so it's absent in the current issue.Currenly mathescape
restores catcode for $
, ^
, and _
, but math material may also contain &
in an math array, see https://tex.stackexchange.com/q/625732.
Note the mathescape
option from listings
package already restores catcode of &
between $...$
.
\documentclass{article}
\usepackage{amsmath}
\usepackage{listings}
\usepackage{minted}
\begin{document}
\subsection*{Actual}
\begin{Verbatim}[commandchars=\\\{\}, mathescape]
# catcode of & = $\text{\the\catcode`\&}, \begin{vmatrix} a & b \\ c & d \end{vmatrix}$
\end{Verbatim}
\makeatletter
% This patches fvextra option "mathescape", but unfortunately it won't work
% for minted, since the pygments-generated (till v2.16.1) "Verbatim" env
% always drop "mathescape" option and use its own "codes={...}" settings.
%
% See https://github.com/pygments/pygments/issues/1988
\appto\FV@MathEscape{\catcode`\&=4\relax}
\makeatother
\subsection*{With workaround}
% NOTE:
% Using "mathescape" now causes all occurances of $, ^, _, and in addition &
% gain their normal catcodes in verbatim content.
\begin{Verbatim}[commandchars=\\\{\}, mathescape, breaklines]
# Verbatim with mathescape, now \& outside of \$...\$ has to be escaped
# catcode of \& = $\text{\the\catcode`\&}, \begin{vmatrix} a & b \\ c & d \end{vmatrix}$
\end{Verbatim}
\begin{Verbatim}[breaklines]
# Verbatim, no mathescape
# catcode of & = $\text{\the\catcode`\&}, \begin{vmatrix} a & b \\ c & d \end{vmatrix}$
\end{Verbatim}
\subsection*{\Verb|lstlisting| env}
\begin{lstlisting}[basicstyle=\ttfamily, escapeinside=||, mathescape, breaklines]{python}
# catcode of & = $\text{\the\catcode`\&}, \begin{vmatrix} a & b \\ c & d \end{vmatrix}$
\end{lstlisting}
\end{document}
Proposal:
diff --git a/fvextra/fvextra.dtx b/fvextra/fvextra.dtx
index 612c885..c99e34b 100644
--- a/fvextra/fvextra.dtx
+++ b/fvextra/fvextra.dtx
@@ -4159,7 +4159,7 @@
\define@booleankey{FV}{mathescape}%
{\let\FancyVerbMathEscape\FV@MathEscape}%
{\let\FancyVerbMathEscape\relax}
-\def\FV@MathEscape{\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}
+\def\FV@MathEscape{\catcode`\$=3\catcode`\&=4\catcode`\^=7\catcode`\_=8\relax}
\FV@AddToHook\FV@CatCodesHook\FancyVerbMathEscape
\fvset{mathescape=false}
% \end{macrocode}
Just a reminder so the idea won't get lost.
At some point, it may be worth adding a
tabstospaces
or similar option that would convert all tabs into spaces. This would allowfvextra
's\Verb*
to be configured exactly as\verb*
. That might require reworking some of the space-dependent line-breaking algorithms, however.Originally posted by @gpoore in #19 (comment)
\documentclass{article}
\usepackage{fvextra, xcolor}
\begin{document}
Case 1. normal
\begin{Verbatim}[frame=single]
line one
line two
line three
\end{Verbatim}
Case 2. the highlight colorbox is \verb|\fboxsep| longer than normal lines,
causing the colorbox bled
\begin{Verbatim}[highlightlines={2}, frame=single]
line one
line two
line three
\end{Verbatim}
Case 3. the highlighted line is \verb|\fboxsep| shorter than normal lines,
causing right list frame not aligned
\begin{Verbatim}[frame=single, highlightlines={2}, breaklines=true]
line one
line two
line three
\end{Verbatim}
\end{document}
I guess this is caused by
\FancyVerbHighlightLineFirst
is defined andframe
, breaklines
, and "highlightlines" act,since something like "the width of line" is miscalculated.
I tried adding an extra \hspace{\FV@TmpLength}
right after the \colorbox
of \FancyVerbHighlightLineFirst
and its families, and this solved the case 3 temporary. I think the complete solution may need some digging into the codes behind \FV@RightListFrame@Single
and option breaklines
, as well as some related toggles.
fvextra v1.3.1 and fancyvrb v2.8 are loaded.
I'm sorry for my disturbing if this kind of combination of options is not the right or recommended manner.
When using fvextra (via minted) with the Libertine font package, I get the following error message:
/usr/local/texlive/2016/texmf-dist/tex/latex/fvextra/fvextra.sty:562: Undefined control sequence \mdseries@tt.
/usr/local/texlive/2016/texmf-dist/tex/latex/fvextra/fvextra.sty:562: leading text: ...FV@BreakSymbolIndentLeft}{\ttfamily xxxx}
The Libertine fonts depend on the mweights package for font configuration, but mweights uses the \AtBeginDocument
command to delay some parts of the font setup.
It seems that the \settowidth
command on line 562 is failing because the font configuration is not complete at the time that fvextra tries to compute these widths.
The following LaTeX document can be used to reproduce the error:
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{libertine}
\usepackage{minted}
\begin{document}
\begin{minted}{c}
int main(int argc, char *argv[]) {
return 0;
}
\end{minted}
\end{document}
Hi, I copy myself from TeX-SX. I think I have an idea that maybe can be implemented (I'm not sure) in fvextra
and it's relative to the following. By entering something like this:
\begin{Verbatim}
some code here
\end{Verbatim}% text before close in the same line
You get:
! FancyVerb Error:
Extraneous input `% text before close in the same line\end{}' between \end{Ve
rbatim} and line end
.
\FV@Error ... {FancyVerb Error:
\space \space #1
}
l.24 ...batim}% text before close in the same line
This is quite different from what you get with standard verbatim
environment or listings
package where the text following from \end{environment}
is placed on the next line. On the other hand, the verbatim
package shows the message:
LaTeX Warning: Characters dropped after `\end{verbatim}' on input line ...
David Carlise proposed a response modifying the error message to:
\makeatletter
\def\FV@BadEndError{%
\@warning
{Extraneous input between
\string\end{\FV@EnvironName} and line end}%
\let\next\FV@EndScanning}
%\makeatother
and in the comments explains the reason for this. I don't know if it will be feasible (valid) to be able to modify the Error
to a Warning
or simply ignore the content when finishing the environment with a %
comment. While it is true that you can put it somewhere else and avoid syntax error, it is also valid to put comments at the end of an environment without these affect the output of the document. This is my example comparison file:
\documentclass{article}%
%\usepackage{verbatim}\newenvironment{myverbatim}{\verbatim}{\endverbatim}
\usepackage{newvbtm}\newverbatim{mynewvbtm}{}{}{}{}
\usepackage{listings}\lstnewenvironment{mylistings}{\lstset{basicstyle=\ttfamily}}{}
\usepackage{fancyvrb}
%\makeatletter
%\def\FV@BadEndError{%
% \@warning
% {Extraneous input between
% \string\end{\FV@EnvironName} and line end}%
% \let\next\FV@EndScanning}
%\makeatother
\DefineVerbatimEnvironment{myfancyvrb}{Verbatim}{}
\begin{document}
\noindent\hrulefill
This text is found just before opening the verbatim (default, no package) environment
\begin{verbatim}
default verbatim environment
\end{verbatim}This text is found just after closing verbatim environment
\noindent\hrulefill
This text is found just before opening the verbatim (with listings package) environment
\begin{mylistings}
verbatim with listings package
\end{mylistings}This text is found just after closing verbatim environment
\noindent\hrulefill
This text is found just before opening the verbatim environment
\begin{mynewvbtm}
verbatim with newvbtm package
\end{mynewvbtm}This text is found just after closing verbatim environment
\noindent\hrulefill
%This text is found just before opening the verbatim (with verbatim package) environment
%\begin{myverbatim}
% LaTeX Warning: Characters dropped after ... on input line...OK
%\end{myverbatim}This text is found just after closing verbatim environment
%\noindent\hrulefill
This text is found just before opening the verbatim (with myfancyvrb package) environment
\begin{myfancyvrb}
A FancyVerb
\end{myfancyvrb}This text is found just after closing verbatim environment
\end{document}
It's just an idea anyway.
Thank you for your great work.
Greetings
See incorrect behavior of \mintinline
within another command at https://tex.stackexchange.com/q/708210/10742.
Since a few days, I noticed that the spaces after commas in my minted environments, with the "text" language, have disappeared.
This issue started after upgrading fvextra to version 1.6.
Here is a MWE:
\documentclass{article}
\usepackage{fvextra}
\begin{document}
\begin{Verbatim}
1, 2, 3, 4, etc
\end{Verbatim}
\end{document}
When compiled, the output appears as: 1,2,3,4,etc
(spaces after commas are not rendered).
The same example, with the previous 1.5 version (or with fancyvrb loaded without fvextra) is rendered as expected: 1, 2, 3, 4, etc
For a long time, compared to their un-starred versions, \verb*
command and verbatim*
environment only print spaces visible. But since the recently released LaTeX2e 2022-11-01, they print both spaces and tabs visible (see latex3/latex2e#1136), which makes the behavior in LaTeX format and in fvextra
package different.
fvextra
package may need to either document the difference or update its behavior.
I've mailed the same info to Herbert Voß, the current maintainer of fancyvrb
.
\documentclass{article}
\usepackage{fvextra}
%\usepackage{fancyvrb}
\parindent=0pt
\begin{document}
\subsection*{\Verb|\verb| from the format}
\verb|xtab tab,sp sp|
\verb*|tab tab,sp sp|
\subsection*{\Verb|\Verb| from \texttt{fvextra}}
\Verb|xtab tab,sp sp|
\Verb*|tab tab,sp sp|
\Verb*[showtabs]|tab tab,sp sp| % perhaps the new behavior for starred version
\end{document}
Hey
I seem to be getting this error when using fvextra with minted. Tried a search on google and couldn't find anyone with a similar problem.
Would appreciate any help or advice on how to fix it.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.