opened
gpoore
username_0
`obeytabs` is incompatible with `breaklines`. The fundamental problem is that `fancyvrb`'s implementation of `obeytabs` uses `\FV@TrueTab`, which uses `\hbox` and conflicts with the line breaking code.

The discovery of the issue was prompted by [this TeX.SE question](http://tex.stackexchange.com/questions/283996/minted-fails-with-breaklines-and-obeytabs). **The next version of `minted` will give an error if `obeytabs` and `breaklines` are used together.**

The proper solution is to have code that scans the beginning of a line token by token, collecting `\FV@Space` and `\FV@Tab`, and replacing them with appropriate characters using appropriate tab stops. This is doable and shouldn't be terribly complex. However, it is different from the current approach used in `fancyvrb`, so it would require either a new verbatim package, or a significant patch of `fancyvrb`. Getting this to work with line breaking, particularly `breakanywhere`, could also be a little tricky in terms of making sure the order of operations is correct.

If there is an attempt to patch `fancyvrb`, it should be noted that the current use of tabs is also problematic in other ways. In particular, on line 605,
```latex
\def\FancyVerbFormatLine#1{\FV@ObeyTabs{#1}}
```
This means that redefining `\FancyVerbFormatLine`, which should be a user command, will break tabbing. The proper way to do this is probably to have `\FancyVerbFormatLine`, which applies to the entire line, and `\FancyVerbFormatText`, which applies only to the text, and to use these two in such a way that their implementation doesn't interfere with the internals. Again, that could involve significant patching.

A diff of changes made while trying to work around this is given below (this is off of 2eef990). Some of this may be useful in the future, but a completely different approach will probably be better.

```diff
diff --git a/source/minted.sty b/source/minted.sty
index 56e8c2c..b788c23 100644
--- a/source/minted.sty
+++ b/source/minted.sty
@@ -816,6 +816,7 @@
         \let\FV@Next=\FV@GetLineIndent
       \else
         \let\FV@Next=\FV@CleanRemainingChars
+        \g@addto@macro{\FV@LineIndentChars}{\relax}%
       \fi
     \fi
   \fi
@@ -831,18 +832,29 @@
 \gdef\FV@Break@Scan{%
   \@ifnextchar\FV@EndBreak%
    {}%
-   {\ifx\@let@token$\relax
-      \let\FV@Break@Next\FV@Break@Math
+   {\ifx\@let@token\FV@Space\relax
+      \let\FV@Break@Next\FV@Break@Whitespace
     \else
-      \ifx\@let@token\bgroup\relax
-        \let\FV@Break@Next\FV@Break@Group
+      \ifx\@let@token\FV@Tab\relax
+        \let\FV@Break@Next\FV@Break@Whitespace
       \else
-        \let\FV@Break@Next\FV@Break@Token
+        \ifx\@let@token$\relax
+          \let\FV@Break@Next\FV@Break@Math
+        \else
+          \ifx\@let@token\bgroup\relax
+            \let\FV@Break@Next\FV@Break@Group
+          \else
+            \let\FV@Break@Next\FV@Break@Token
+          \fi
+        \fi
       \fi
     \fi
     \FV@Break@Next}%
 }
 \endgroup
+\gdef\FV@Break@Whitespace#1{%
+  \g@addto@macro{\FV@Tmp}{#1}%
+  \FV@Break@Scan}
 \begingroup
 \catcode`\$=3%
 \gdef\FV@Break@Math$#1${%
@@ -935,8 +947,8 @@
       \ifthenelse{\boolean{FV@BreakAutoIndent}}%
        {\hspace*{-\wd\FV@LineIndentBox}}%
        {}%
-      \strut\FancyVerbFormatText{%
-        \FancyVerbBreakStart#1\FancyVerbBreakStop}\nobreak\strut
+      \strut\FancyVerbFormatText{\expandafter\FV@Break@ObeyTabs\expandafter{%
+        \FancyVerbBreakStart#1\FancyVerbBreakStop}}\nobreak\strut
       \end{internallinenumbers*}
     }%
     \ifdefempty{\FancyVerbBreakSymbolRight}{}%
@@ -957,6 +969,8 @@
     \advance\linewidth by -\FV@FrameRule
   \fi
   \sbox{\FV@LineBox}{\FancyVerbFormatLine{\FancyVerbFormatText{#1}}}%
+  \let\FV@Break@ObeyTabs\FV@ObeyTabs
+  \let\FV@ObeyTabs\relax
   \ifdim\wd\FV@LineBox>\linewidth
     \setcounter{FancyVerbLineBreakLast}{0}%
     \FV@SaveLineBox{#1}%
@@ -972,10 +986,12 @@
     \FV@LeftListNumber
     \FV@LeftListFrame
     \FancyVerbFormatLine{%
-      \parbox[t]{\linewidth}{\noindent\strut\FancyVerbFormatText{#1}\strut}}%
+      \parbox[t]{\linewidth}{\noindent\strut%
+        \FancyVerbFormatText{\FV@Break@ObeyTabs{#1}}\strut}}%
     \FV@RightListFrame
     \FV@RightListNumber
-  \fi}%
+  \fi
+  \let\FV@ObeyTabs\FV@Break@ObeyTabs}%
   \hss}\baselineskip\z@\lineskip\z@}
 \ifcsname KV@FV@linenos\endcsname\else
 \define@booleankey{FV}{linenos}%
```
obeytabs and breaklines
issue
created
gpoore
username_0
`obeytabs` also doesn't work with multiline comments (#88), so I'm renaming the issue to be broader.
comment
created
gpoore
username_0
If this is resolved, then an option for customizing the tab character should be added. For example, see #98.
comment
created
gpoore
username_0
The new [`fvextra` package](https://github.com/username_0/fvextra) fixes the incompatibility between `breaklines` and `obeytabs`. It also adds a `tab` option for redefining the tab character.

The incompatibility with tabs inside multiline comments remains. This might be resolved by having the `\PYG` comment macros look ahead and relocate any leading whitespace. Another option would be to attempt a special version of `\FV@TrueTab` that can handle this scenario correctly.
comment
created
gpoore
username_0
All of these tab issues are resolved in [v2.3](https://github.com/username_0/minted/releases/tag/v2.3). Essentially everything is fixed by [`fvextra`](https://github.com/username_0/fvextra), except that `obeytabs` doesn't use correct tab stops for tabs preceded by anything other than spaces or tabs. Fixing that is beyond what the current tab expansion algorithms can handle. There are notes about what would be required for a better algorithm in the `fvextra` implementation.
comment
closed
gpoore
username_0
issue