Text FormattingAuto bulleting with new line

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
fluidFreak
Posts: 1
Joined: Sun Feb 28, 2016 8:48 am

Auto bulleting with new line

Post by fluidFreak »

Hey!

I have a quite long text example, which needs to be put in itemize or enumerate environment by every newline or something similar.
Lets assume that I'm too lazy :) to write \item in every new line that needs to be bulleted. In old times, when I was using Word, which I don't anymore, things went like: mark the text, click the bulleting icon.
Is this a problem that can be solved within Latex or within the writing program (I'm using TeXstudio)?

Thanks for the advice.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

Auto bulleting with new line

Post by Stefan Kottwitz »

Welcome to the forum!

Stephan Lembke had the idea for some macros to solve this. Here, you get two commands \startitems and \stopitems, which you could put in your preamble or use via \input. This converts your lines to bulleted lines.

Simple but complete example:

Code: Select all

\documentclass{article}
\makeatletter
\newcommand{\startitems}{%
  \begingroup
  \parindent\z@
  \@itemdepth\@ne
  \@totalleftmargin\csname leftmargin\romannumeral\the\@itemdepth\endcsname
  \leftskip\@totalleftmargin
  \everypar
  {%
    \llap{%
      \makebox[\labelsep][l]
      {%
        \csname labelitem\romannumeral\the\@itemdepth\endcsname
      }
    }%
  }%
  \obeylines%
}
\newcommand{\stopitems}{%
  \ifnum\@itemdepth>\@ne
    \down\bottom
  \fi
  \par\endgroup%
}
\makeatother
\begin{document}
\startitems
One
Two
Three
Four
\stopitems
\end{document}
If you would like to have it more complex, with sub items, Stephan has more code here:

Code: Select all

\documentclass{article}

\makeatletter

\newcommand\startitems
{%
  \begingroup
  \parindent\z@
  \@itemdepth\@ne
  \@totalleftmargin\csname leftmargin\romannumeral\the\@itemdepth\endcsname
  \leftskip\@totalleftmargin
  \everypar
  {%
    \llap{%
      \makebox[\labelsep][l]
      {%
        \csname labelitem\romannumeral\the\@itemdepth\endcsname
      }
    }%
  }%
  \obeylines
}
\newcommand\stopitems
{%
  \bottom
  \par\endgroup
}

\newcommand\up
{%
  \par
  \begingroup
    \advance\@itemdepth\@ne
    \advance\@totalleftmargin\csname leftmargin\romannumeral\the\@itemdepth\endcsname
    \leftskip\@totalleftmargin
}

\newcommand\down{\par\endgroup}

\newcommand\bottom
{%
  \ifnum\@itemdepth>\@ne
    \down\bottom
  \fi
}

\makeatother

\begin{document}

\section*{title}
\startitems
this is a line of text
this is another line of text
\up
this is a subpoint
another
\up
sub-sub  point
\bottom
back to first level
\stopitems

\noindent Normal text
\end{document}
This sample gives:
list.png
list.png (5.87 KiB) Viewed 2326 times
Gets more complicated. :) The first code which I simplified, is enough for your purpose. The LaTeX equivalent to mark and click is surounding your list by \startitems and \stopitems.

Stefan
LaTeX.org admin
Post Reply