4

I'd like to redefine the \lipsum command provided by the lipsum package such that \lipsum{} outputs not a predefined amount of lorem ipsum paragraphs, but a single, random, lorem ipsum paragraph (that is, a paragraph that is each time picked randomly from the 150 provided by the package).

I figured using \usepackage[first=1,last=150]{lcg} would allow me to get a random integer 0 < i < 151.

My MWE is this:

\documentclass{article}
\usepackage[first=1,last=150]{lcg}
\usepackage{lipsum}

\let\oldl\lipsum
\renewcommand{\lipsum}{%
  \rand% as far as I could understand from the lcg documentation, each time this is called the \rand counter is assigned a new integer in the interval previously specified
  \newcommand{\Rand}{\value{\rand}}% thought this would be necessary to ensure that the optional argument passed to \oldl is expanded a single time, like the lipsum documentation describes as mandatory; is this correct?
  % BTW: is it ok to define a command inside the definition of a command?
  \oldl[\Rand]%
}

\begin{document}
I am a random sample text:

\lipsum{}

\end{document}

The error I get suggests there's something wrong with how the macros are expanded, but I can't find out what exactly is wrong.

PS.: I realize that such shortcut for typing some garbage text is an overkill; I'm more interested in why my MWE doesn't work as intended as to actually making such new \lipsum command work.

0

1 Answer 1

7

I wouldn't redefine \lipsum

\documentclass{article}
\usepackage[first=1,last=150]{lcg}
\usepackage{lipsum}

\newcommand{\randlipsum}{%
  \rand % store a random integer in rand
  \lipsum[\arabic{rand}]%
}

\begin{document}
I am a random sample text:

\randlipsum

\end{document}

The fact is that \lipsum wants to see an explicit number (after macro expansion) in its argument, not a counter value.

1
  • You kantlipsum can you?
    – percusse
    May 16, 2018 at 9:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .