lipsum – Easy Methods for Obtaining Lorem Ipsum Text in LaTeX

lipsum

Many questions use lorem ipsum filler text from package lipsum. I am testing a regex script on text files nested within different folders. For this and to improve LaTeX understanding better I would like to output lipsum text into a plain text file.

A manual way is to run a LaTeX engine (say pdflatex), open the pdf and copy and paste into a plain text document. The \usepackage[T1]{fontenc} line have added to aid copying, but am unsure if this makes a difference to the lorem ipsum text.

Here are two ideas, but I do not know if these are feasible methods nor how to implement them if they are.

  1. Use pdflatex (or other command) flags.
  2. Use TeX command line tools to identify the file location within the lipsum package where the lorem ipsum text is located.

From these the lorum ipsum text could be obtained and redirected to a text file.

The functionality to vary the amount of lorum ipsum text may also be helpful, for example if output to three files they could each have a different amount of filler text. This would rule out 2. above.

The accepted answer here Is it possible to generate a set amount of words using lipsum? says “the output of \lipsum is protected, so the only way get the text is to copy it from a previous PDF”. An explanation of this is also welcome.

Best Answer

You can use \unpacklipsum:

\documentclass{article}
\usepackage{lipsum}

\newwrite\lipsum
\immediate\openout\lipsum=\jobname.txt

\unpacklipsum[1]
\immediate\write\lipsum{\lipsumexp}

\stop

The generated file will be

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida mauris. Nam arcu libero, nonummy eget, consectetuer id, vulputate a, magna. Donec vehicula augue eu neque. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Mauris ut leo. Cras viverra metus rhoncus sem. Nulla et lectus vestibulum urna fringilla ultrices. Phasellus eu tellus sit amet tortor gravida placerat. Integer sapien est, iaculis in, pretium quis, viverra ac, nunc. Praesent eget sem vel leo ultrices bibendum. Aenean faucibus. Morbi dolor nulla, malesuada eu, pulvinar at, mollis ac, nulla. Curabitur auctor semper nulla. Donec varius orci eget risus. Duis nibh mi, congue eu, accumsan eleifend, sagittis quis, diam. Duis eget orci sit amet orci dignissim rutrum.