Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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 ?

share|improve this question
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 0: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 0: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 7: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 7:10
show 5 more comments

2 Answers

up vote 3 down vote accepted

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}
share|improve this answer
    
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 1 '12 at 0:24
    
Have saw it. But Why did you take of the space ? It's more pretty, no ? –  Julien Jun 1 '12 at 0:28
show 6 more comments

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}
share|improve this answer
    
Would be perfect if the bullet of the subindent was indented too. –  Julien May 31 '12 at 11:10
1  
@Julien: Yep, that is exactly what the first point in the "Further Enhancements" section was referring to. –  Peter Grill May 31 '12 at 19:12
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.