2

Actually, isn’t not really a question. (Since my examinations get close, I don't really have the time to search for a solution to my problems.)

Rather than using the common \item, I'd like to use simple tabulation, with the possibility to indent. I know it isn't really the spirit of latex, but I want to fuse "Word" document with LaTeX one, to make them more pretty, and there are a lot of "itemized" item. And they ate a lot of time.

I was thinking of the use of special environment, or may be the "WYSIWYG" mode of LaTeX (normally used to show LaTeX code, for example), the verbatim environment (but "what" for the "arrow", or point or what ever that show the element ?).

It may be more cleare with this image ; upper part of the image = "in LaTeX", down part of the image = "PDF result"

Please don't mind the underlingment in the picture.

Edit :

Here, I just play a little with the code, and it give this : After few test

The "new" code (originally from Peter Grill) :

\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}

I've added some \hpsace, and put one instead of a simple \space. It makes the word more clear. I don't know what is the {\ } for in the begining of \lstset{literate=% {\ }{{{\ProcessSpace}}}1% Count contigous spaces, but it seems (or may be the "bullet" part), that this is the cause of the first word splitting. When I add an \ in it, no bullet anymore, but the word were correctly put.

Any idea ? (Again, thanks for the answers)

Edit 2 :

Thanks to Peter Grill's code, problem solved.

Note : This system doesn't allow the use of macro inside the list.

What about "enumerate" now ?

Julien
  • 865
  • 1
  • 9
  • 16
  • 3
    It is not entirely clear what you're after: Do you want to create a itemize-like structure that is actually done inside a tabular? itemize (or lists in general) is far less complex than tables, so they are much quicker to construct. And what is the "quid"? – Werner May 30 '12 at 23:07
  • 'It is not entirely clear what you're after: Do you want to create a itemize-like structure that is actually done inside a tabular?' Actually, yes, somehow. About the quid, it's from my motherthongue (it's the right word ?), I didn't translate it immediatly, sorry. If you already have used "Word", or Openoffice, or whatever, try to remember the systeme for listing. I'd like to make more or less the same, for the entry. – Julien May 31 '12 at 00:12
  • 1
    Perhaps a picture/image of your desired output would help make your question clearer? It is possible to 'indent' in a table cell in a few different ways. – jon May 31 '12 at 00:42
  • Possible duplicate: Using indentation to automatically begin and end itemize environments; related: Automatically itemize a paragraph. Please take a look at these and report back if this is what you are after. – Daniel May 31 '12 at 07:01
  • 1
    Also take a look at the easylist package. While it does not support tabs as indentation markers out of the box, it possibly could be extended in that way. Maybe you could also live with marking the indentation by something like +, ++ and so on. – Daniel May 31 '12 at 07:10
  • @ Daniel : The annoying part with the LaTeX list are that I've got to put something, to each single item. When you have to treat more than 50 just for one page... You easly get mad. So, those solution wouldn't help me. Thanks. – Julien May 31 '12 at 11:08
  • There are many text editors that make things easier. For example, using TextMate, if I press Enter (as opposed to Return) inside of a list environment I get a new line with an \item at the front and then the caret. – Dylan Moreland Jun 01 '12 at 00:28
  • Yes, it be nice, but most of the time, text is already made, and this is the reason I don't want to re-type it with "Enter", "+", etc. – Julien Jun 01 '12 at 01:50
  • You might consider writing an outline→LaTeX preprocessor in a language better suited to text manipulation. Peter's solution looks pretty nice, though! – Dylan Moreland Jun 01 '12 at 16:28
  • Well, she is. It works fine. Exactly what I needed. – Julien Jun 02 '12 at 20:06

2 Answers2

4

Here is something that I think is more promising and even changes the leading character based on spaces. So, using the input as

\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}

yields:

enter image description here

This code uses literate from the listings package to count the number of contiguous spaces. When a non-space character is encountered, and the number of contiguous spaces encountered was more than 4, then a leading character is inserted based on the range of the number of spaces.

Notes:

  • There appears to be a problem with the default case of \IfEqCase, so if more tab stops are required that portion of the code will need to be updated to select an appropriate character. I have extended the code to include a few more levels, but be aware of this in case even more are needed.
  • Based on the solution to How to detect a tab character when processing a literate in lstlistings?, this now works with tabs used for indentation as opposed to spaces.

Code:

\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}

Peter Grill
  • 223,288
  • The LaTeX for the list is what I want. For the render, adding space between bullet and keeping a "normal" aspect for the text would be better. Are those the problems you mentionned ? About the change of bullet, it isn't necessary. But would it work for enumerate either ? – Julien May 31 '12 at 11:16
  • @Julien: Yep, this is exactly the point mentioned in "Issues" section. I do not know what the problem is at this time. This could probably be adapted for enumerate as well, but would require more work. Also, not sure what you meant by your comment "The LaTeX for the list is what I want". The code before begin{document} would presumably go in your preamble, so you could just type in the list as shown in the lstlisting environment. – Peter Grill May 31 '12 at 19:16
  • The LaTeX code between '\begin{document}' and '\end{document}' look excatly like what I want. – Julien May 31 '12 at 20:43
  • @Julien: Have updated the answer and even used your new MWE code to make it complete. – Peter Grill Jun 01 '12 at 00:24
  • Have saw it. But Why did you take of the space ? It's more pretty, no ? – Julien Jun 01 '12 at 00:28
  • Ok, have updated it to include the space. – Peter Grill Jun 01 '12 at 00:36
  • Now, what's the difference between tabulation (from the keybord) and space ? Is there a way to count as well the tabulation , rather than the 4 spaces (If you say no, well, your answer the one, thanks !) ? 6 levels is already good, but if we don't change the bullet for the others, could it be possible not to have to update for more levels ? – Julien Jun 01 '12 at 00:51
  • @Julien: I don't know, but perhaps you should post a separate question as to how to detect a tab character. Adding tabsize=4, keepspaces=true, helps, but the literate need to be able to detect a tab and increment the number of contiguous spaces appropriately. I will update the code to be able to do this so when we figure out how to detect the tab it'll be an easy fix. – Peter Grill Jun 01 '12 at 00:55
  • @: Peter : Actually, there something from Martin Scharrer (http://tex.stackexchange.com/a/21613/13993), where it have done something like that, for verbatim, using the listing package. Don't really understand it, but it might help. – Julien Jun 01 '12 at 01:13
  • Hmmm... Thought I found the solution to be lstag@tabulator, but am getting strange behavior. Have to go now but will experiment some more later and if I still can't figure it out I will post a new question. – Peter Grill Jun 01 '12 at 01:32
  • Thank you very much, it's work well and save my time. You were speaking of the possibility to do the same for enumeration. What would it be ? – Julien Jun 02 '12 at 02:33
2

Here is a partial solution using FancyVerbFormatLine from the fancyverb package to achieve:

enter image description here

Further Enhancements:

The following are needed to get the complete desired behavior:

  • print the character before the first non-space char, as opposed to the beginning of the line.
  • change the character based on the number of spaces.

Code:

\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}

Peter Grill
  • 223,288