使用制表系统使项目的逐项化更加容易

使用制表系统使项目的逐项化更加容易

其实,这并不是一个问题。(由于考试临近,我并没有时间去寻找问题的答案。)

我不想使用常见的\item,而是想使用简单的制表符,并可以缩进。我知道这不符合 Latex 的本质,但我想将“Word”文档与 LaTeX 文档融合在一起,使它们更漂亮,而且有很多“分项”项目。而且它们浪费了很多时间。

我正在考虑使用特殊环境,或者可能是 LaTeX 的“所见即所得”模式(例如,通常用于显示 LaTeX 代码),逐字环境(但“什么”代表“箭头”,或点或任何显示元素的东西?)。

这张图片可能更清楚;图像的上半部分 = “在 LaTeX 中”,图像的下半部分 = “PDF 结果”

请不要介意图片中的下划线。

编辑 :

在这里,我只是稍微玩了一下代码,它给出了这样的结果: 经过几次测试

“新”代码(最初是从彼得·格里尔):

\documentclass{article}
\usepackage{pgf}
\usepackage{xstring}
\usepackage{listings}

\newcounter{NumOfContigousSpaces}%
\setcounter{NumOfContigousSpaces}{0}%

\newcommand{\Width}{1}%
\newcommand*{\AddApproriateBulletIfFirstChar}[1]{%
    \pgfmathtruncatemacro{\BulletType}{\arabic{NumOfContigousSpaces}/4}%
    \IfEqCase{\BulletType}{%
        {0}{\gdef\Width{1}}
        {1}{\gdef\Width{3}$\bullet$\hspace{1em}}
        {2}{\gdef\Width{3}$\circ$\hspace{1em}}
        {3}{\gdef\Width{3}$\star$\hspace{1em}}
    }[\gdef\Width{3}$\bullet$\hspace{1em}]%
    #1%
    \setcounter{NumOfContigousSpaces}{0}%
}%
\newcommand*{\ProcessSpace}{%
    \stepcounter{NumOfContigousSpaces}%
    \hspace{4em}%
}%
\lstset{literate=%
    {\ }{{{\ProcessSpace}}}1% Count contigous spaces
    {a}{{{\AddApproriateBulletIfFirstChar{a}}}}\Width
    {b}{{{\AddApproriateBulletIfFirstChar{b}}}}\Width
    {c}{{{\AddApproriateBulletIfFirstChar{c}}}}\Width
    {d}{{{\AddApproriateBulletIfFirstChar{d}}}}\Width
    {e}{{{\AddApproriateBulletIfFirstChar{e}}}}\Width
    {f}{{{\AddApproriateBulletIfFirstChar{f}}}}\Width
    {g}{{{\AddApproriateBulletIfFirstChar{g}}}}\Width
    {h}{{{\AddApproriateBulletIfFirstChar{h}}}}\Width
    {i}{{{\AddApproriateBulletIfFirstChar{i}}}}\Width
    {j}{{{\AddApproriateBulletIfFirstChar{j}}}}\Width
    {k}{{{\AddApproriateBulletIfFirstChar{k}}}}\Width
    {l}{{{\AddApproriateBulletIfFirstChar{l}}}}\Width
    {m}{{{\AddApproriateBulletIfFirstChar{m}}}}\Width
    {n}{{{\AddApproriateBulletIfFirstChar{n}}}}\Width
    {o}{{{\AddApproriateBulletIfFirstChar{o}}}}\Width
    {p}{{{\AddApproriateBulletIfFirstChar{p}}}}\Width
    {q}{{{\AddApproriateBulletIfFirstChar{q}}}}\Width
    {r}{{{\AddApproriateBulletIfFirstChar{r}}}}\Width
    {s}{{{\AddApproriateBulletIfFirstChar{s}}}}\Width
    {t}{{{\AddApproriateBulletIfFirstChar{t}}}}\Width
    {u}{{{\AddApproriateBulletIfFirstChar{u}}}}\Width
    {v}{{{\AddApproriateBulletIfFirstChar{v}}}}\Width
    {w}{{{\AddApproriateBulletIfFirstChar{w}}}}\Width
    {x}{{{\AddApproriateBulletIfFirstChar{x}}}}\Width
    {y}{{{\AddApproriateBulletIfFirstChar{y}}}}\Width
    {z}{{{\AddApproriateBulletIfFirstChar{z}}}}\Width
    %--- now handle uppercase chars
    {A}{{{\AddApproriateBulletIfFirstChar{A}}}}\Width
    {B}{{{\AddApproriateBulletIfFirstChar{B}}}}\Width
    {C}{{{\AddApproriateBulletIfFirstChar{C}}}}\Width
    {D}{{{\AddApproriateBulletIfFirstChar{D}}}}\Width
    {E}{{{\AddApproriateBulletIfFirstChar{E}}}}\Width
    {F}{{{\AddApproriateBulletIfFirstChar{F}}}}\Width
    {G}{{{\AddApproriateBulletIfFirstChar{G}}}}\Width
    {H}{{{\AddApproriateBulletIfFirstChar{H}}}}\Width
    {I}{{{\AddApproriateBulletIfFirstChar{I}}}}\Width
    {J}{{{\AddApproriateBulletIfFirstChar{J}}}}\Width
    {K}{{{\AddApproriateBulletIfFirstChar{K}}}}\Width
    {L}{{{\AddApproriateBulletIfFirstChar{L}}}}\Width
    {M}{{{\AddApproriateBulletIfFirstChar{M}}}}\Width
    {N}{{{\AddApproriateBulletIfFirstChar{N}}}}\Width
    {O}{{{\AddApproriateBulletIfFirstChar{O}}}}\Width
    {P}{{{\AddApproriateBulletIfFirstChar{P}}}}\Width
    {Q}{{{\AddApproriateBulletIfFirstChar{Q}}}}\Width
    {R}{{{\AddApproriateBulletIfFirstChar{R}}}}\Width
    {S}{{{\AddApproriateBulletIfFirstChar{S}}}}\Width
    {T}{{{\AddApproriateBulletIfFirstChar{T}}}}\Width
    {U}{{{\AddApproriateBulletIfFirstChar{U}}}}\Width
    {V}{{{\AddApproriateBulletIfFirstChar{V}}}}\Width
    {W}{{{\AddApproriateBulletIfFirstChar{W}}}}\Width
    {X}{{{\AddApproriateBulletIfFirstChar{X}}}}\Width
    {Y}{{{\AddApproriateBulletIfFirstChar{Y}}}}\Width
    {Z}{{{\AddApproriateBulletIfFirstChar{Z}}}}\Width
}
\begin{document}
\begin{lstlisting}
Not indent one
    What a want to indent
    Others stuff
        And subindent
        Again other
            And even more subindent
            More and more
    Another thing
    Last one
\end{lstlisting}
\end{document}

我添加了一些\hpsace,并用一个 代替了一个简单的\space。这样可以让单词更清晰。我不知道{\ }开头的 for是什么\lstset{literate=% {\ }{{{\ProcessSpace}}}1% Count contigous spaces,但似乎(或可能是“项目符号”部分)是第一个单词拆分的原因。当我在其中添加 \ 时,不再有项目符号,但单词被正确放置了。

有什么想法吗?(再次感谢您的回答)

编辑2:

谢谢彼得·格里尔的代码,问题解决了。

笔记:本系统不允许在列表内使用宏。

那么“枚举”现在怎么样?

答案1

我觉得这里有一个更有前途的方法,甚至可以根据空格改变主要字符。因此,使用输入作为

\begin{lstlisting}[style=MyItemize]
    What a want to indent
    Others stuff
        And subindent
        Again other
                And even more subindent
                    And even more subindent
            More and more
    Another thing
    Last one
\end{lstlisting}

产量:

在此处输入图片描述

此代码使用包literate中的 来listings计算连续空格的数量。当遇到非空格字符,并且遇到的连续空格数超过 4 个时,将根据空格数的范围插入前导字符。

笔记:

  • 的默认大小写似乎存在问题\IfEqCase,因此如果需要更多制表位,则需要更新该部分代码以选择合适的字符。我已扩展代码以包含更多级别,但请注意这一点,以防需要更多级别。
  • 基于解决方案如何在处理列表列表中的文字时检测制表符?,现在可以使用制表符来缩进,而不是使用空格。

代码:

\documentclass{article}
\usepackage{pgf}
\usepackage{xstring}
\usepackage{listings}

\newcounter{NumOfContigousSpaces}%
\setcounter{NumOfContigousSpaces}{0}%

\newcommand{\Width}{1}%
\newcommand*{\AddApproriateBulletIfFirstChar}[1]{%
    \pgfmathtruncatemacro{\BulletType}{\arabic{NumOfContigousSpaces}/4}%
    \IfEqCase{\BulletType}{%
        {0}{\gdef\Width{1}}
        {1}{\gdef\Width{3}$\bullet$ }
        {2}{\gdef\Width{3}$\circ$ }
        {3}{\gdef\Width{3}$\times$ }
        {4}{\gdef\Width{3}$\star$ }
        {5}{\gdef\Width{3}$-$ }
    }[\gdef\Width{3}$\bullet$ ]%
    #1%
    \setcounter{NumOfContigousSpaces}{0}%
}%

\newcommand*{\ProcessSpace}{%
    \addtocounter{NumOfContigousSpaces}{1}%
    \space%
}%
\newcommand*{\ProcessTab}{%
    \addtocounter{NumOfContigousSpaces}{4}%
    \space\space\space\space%
}%

\lstdefinestyle{MyItemize}{%
    basicstyle=\ttfamily,
    columns=flexible,
    tabsize=4, keepspaces=true,
    literate=%
        {\ }{{{\ProcessSpace}}}1% Count contigous spaces
        {\^^I}{{{\ProcessTab}}}4% 
        {a}{{{\AddApproriateBulletIfFirstChar{a}}}}\Width
        {b}{{{\AddApproriateBulletIfFirstChar{b}}}}\Width
        {c}{{{\AddApproriateBulletIfFirstChar{c}}}}\Width
        {d}{{{\AddApproriateBulletIfFirstChar{d}}}}\Width
        {e}{{{\AddApproriateBulletIfFirstChar{e}}}}\Width
        {f}{{{\AddApproriateBulletIfFirstChar{f}}}}\Width
        {g}{{{\AddApproriateBulletIfFirstChar{g}}}}\Width
        {h}{{{\AddApproriateBulletIfFirstChar{h}}}}\Width
        {i}{{{\AddApproriateBulletIfFirstChar{i}}}}\Width
        {j}{{{\AddApproriateBulletIfFirstChar{j}}}}\Width
        {k}{{{\AddApproriateBulletIfFirstChar{k}}}}\Width
        {l}{{{\AddApproriateBulletIfFirstChar{l}}}}\Width
        {m}{{{\AddApproriateBulletIfFirstChar{m}}}}\Width
        {n}{{{\AddApproriateBulletIfFirstChar{n}}}}\Width
        {o}{{{\AddApproriateBulletIfFirstChar{o}}}}\Width
        {p}{{{\AddApproriateBulletIfFirstChar{p}}}}\Width
        {q}{{{\AddApproriateBulletIfFirstChar{q}}}}\Width
        {r}{{{\AddApproriateBulletIfFirstChar{r}}}}\Width
        {s}{{{\AddApproriateBulletIfFirstChar{s}}}}\Width
        {t}{{{\AddApproriateBulletIfFirstChar{t}}}}\Width
        {u}{{{\AddApproriateBulletIfFirstChar{u}}}}\Width
        {v}{{{\AddApproriateBulletIfFirstChar{v}}}}\Width
        {w}{{{\AddApproriateBulletIfFirstChar{w}}}}\Width
        {x}{{{\AddApproriateBulletIfFirstChar{x}}}}\Width
        {y}{{{\AddApproriateBulletIfFirstChar{y}}}}\Width
        {z}{{{\AddApproriateBulletIfFirstChar{z}}}}\Width
        %--- now handle uppercase chars
        {A}{{{\AddApproriateBulletIfFirstChar{A}}}}\Width
        {B}{{{\AddApproriateBulletIfFirstChar{B}}}}\Width
        {C}{{{\AddApproriateBulletIfFirstChar{C}}}}\Width
        {D}{{{\AddApproriateBulletIfFirstChar{D}}}}\Width
        {E}{{{\AddApproriateBulletIfFirstChar{E}}}}\Width
        {F}{{{\AddApproriateBulletIfFirstChar{F}}}}\Width
        {G}{{{\AddApproriateBulletIfFirstChar{G}}}}\Width
        {H}{{{\AddApproriateBulletIfFirstChar{H}}}}\Width
        {I}{{{\AddApproriateBulletIfFirstChar{I}}}}\Width
        {J}{{{\AddApproriateBulletIfFirstChar{J}}}}\Width
        {K}{{{\AddApproriateBulletIfFirstChar{K}}}}\Width
        {L}{{{\AddApproriateBulletIfFirstChar{L}}}}\Width
        {M}{{{\AddApproriateBulletIfFirstChar{M}}}}\Width
        {N}{{{\AddApproriateBulletIfFirstChar{N}}}}\Width
        {O}{{{\AddApproriateBulletIfFirstChar{O}}}}\Width
        {P}{{{\AddApproriateBulletIfFirstChar{P}}}}\Width
        {Q}{{{\AddApproriateBulletIfFirstChar{Q}}}}\Width
        {R}{{{\AddApproriateBulletIfFirstChar{R}}}}\Width
        {S}{{{\AddApproriateBulletIfFirstChar{S}}}}\Width
        {T}{{{\AddApproriateBulletIfFirstChar{T}}}}\Width
        {U}{{{\AddApproriateBulletIfFirstChar{U}}}}\Width
        {V}{{{\AddApproriateBulletIfFirstChar{V}}}}\Width
        {W}{{{\AddApproriateBulletIfFirstChar{W}}}}\Width
        {X}{{{\AddApproriateBulletIfFirstChar{X}}}}\Width
        {Y}{{{\AddApproriateBulletIfFirstChar{Y}}}}\Width
        {Z}{{{\AddApproriateBulletIfFirstChar{Z}}}}\Width
}%

\begin{document}
\begin{lstlisting}[style=MyItemize]
    What a want to indent
    Others stuff
        And subindent
        Again other
                And even more subindent
                    And even more subindent
            More and more
    Another thing
    Last one
\end{lstlisting}
\end{document}

答案2

FancyVerbFormatLine以下是使用该fancyverb包实现的部分解决方案:

在此处输入图片描述

进一步增强:

要获得完整的期望行为,需要以下内容:

  • 打印第一个非空格字符之前的字符,而不是行首。
  • 根据空格数改变字符。

代码:

\documentclass{article}
\usepackage{fancyvrb}

\begin{document}
\renewcommand\FancyVerbFormatLine[1]{\textbullet#1}
\begin{Verbatim}
    What a want to indent
        And subindent
    Another thing
\end{Verbatim}
\end{document}

相关内容