jkuczm / mmacells

Mathematica cells in TeX
63 stars 18 forks source link

Wrong indent with package ctex #19

Closed szsdk closed 8 years ago

szsdk commented 8 years ago

I'm from China. So I need package ctex to input Chines characters. But the indent is strange when I use it with ctex

\documentclass{article}
\usepackage{ctex}
\usepackage{mmacells}

\begin{document}

\begin{mmaCell}{Output}
\{1,2
3,4\}
\end{mmaCell}

\begin{Verbatim}[commandchars=\\\{\}]
\{1,2
3,4\}
\end{Verbatim}

\end{document}
jkuczm commented 8 years ago

Could you add a screenshot of your resulting .pdf?

I'm getting following with your code: screen and I don't see any indentation problems there.

szsdk commented 8 years ago

test And I'm using texlive2015.

jkuczm commented 8 years ago

This again looks like an issue of listings interface with fancyvrb related to this one and ctex somehow interferes with it.

I can reproduce it in TeXLive 2015 with following code:

\documentclass{article}
\usepackage{ctex}
\usepackage{listings}
\usepackage{fancyvrb}

\begin{document}

\lstset{fancyvrb}

\begin{itemize}
  \item
    \begin{Verbatim}
{1,2
3,4}
    \end{Verbatim}
\end{itemize}

\end{document}

I think problems are somewhere in listings \lstFV@VerbatimBegin command, or at least it triggers the problem which is somewhere in \FV@List. I don't know which part of ctex causes changes in fancyvrb + listings behavior inside list environments.

I'm sure there's a better way to fix it, but so far I can propose following workaround, which sets left margin to 0 when processing first line of Verbatim environment:

\documentclass{article}
\usepackage{ctex}
\usepackage{listings}
\usepackage{fancyvrb}

\makeatletter
\def\myIndentFix{%
\def\FV@ListProcessLine@i##1{%
  \hbox{%
    \ifvoid\@labels\else
      \hbox to \z@{\kern\@totalleftmargin\box\@labels\hss}%
    \fi
%% Dirty workaround start
    \leftmargin=0pt
%% Dirty workaround end
    \FV@ListProcessLine{##1}}%
  \let\FV@ProcessLine\FV@ListProcessLine@ii}%
}
\makeatother

\begin{document}

\lstset{fancyvrb}
\begin{itemize}
  \item
    \begin{Verbatim}[listparameters=\myIndentFix]
{1,2
3,4}
    \end{Verbatim}
\end{itemize}

\end{document}

With mmacells it can be used in following way:

\documentclass{article}
\usepackage{ctex}
\usepackage{mmacells}

\makeatletter
\def\myIndentFix{%
\def\FV@ListProcessLine@i##1{%
  \hbox{%
    \ifvoid\@labels\else
      \hbox to \z@{\kern\@totalleftmargin\box\@labels\hss}%
    \fi
%% Dirty workaround start
    \leftmargin=0pt
%% Dirty workaround end
    \FV@ListProcessLine{##1}}%
  \let\FV@ProcessLine\FV@ListProcessLine@ii}%
}
\makeatother

\ExplSyntaxOn
\cs_set_protected_nopar:Npn \__mmacells_fix_labels: {}
\ExplSyntaxOff

\mmaSet{morefv={listparameters=\myIndentFix}}

\begin{document}

\begin{mmaCell}{Output}
\{1,2
3,4\}
\end{mmaCell}

\begin{mmaCell}[label=looooooooooooooooooooooooooooong label]{Output}
\{1,2
3,4\}
\end{mmaCell}

\end{document}
jkuczm commented 8 years ago

Similarly to #18 using uselistings=false option removes indentation problems.