11

My daughter is learning to read; I am learning TeX. So I need your help on this:

I have an array/a list of nouns (basically names of people and two mythical creatures called Fara and Fu:

noun = ["Fu", "Fara", "Uta", "Mama", "Mami", "Ralf", "Lara", "Mara", "Murat", "Marta", "Mamut", "Ira", "Mira", "Maria" ]

Together with this goes a list of verbs she can read:

verb = ["malt", "ruft", "umarmt" ]

I am looking for a way to automatically typeset all possible and sensible permutations of nouns and verb, such as this list my simple ruby script already generates:

Maria umarmt Mama.
Maria malt Uta mit mir.
Mara malt Maria.
Fu malt Mamut.
Marta malt Mama.

By "sensible" I mean not having things like

Fu umarmt Fu.

as it is physically impossible to hug oneself (unless you are James Bond).

Randomly the text " mit mir" (together with me) might be added to each sentence.

Why LaTeX? rubyonly outputs text, and here comes request number two:

The syllables of the words need to be colored blue-red-blue-red-.... for first-second-third-... syllable, such as this:

wortliste

In the name of my daughter (and myself of course) - Thank you!


My current setup as per my comment below:

\documentclass[18pt,oneside,a4paper]{scrartcl}

\usepackage{pgfmath,color}
\usepackage[doublespacing]{setspace}

%Einstellungen der Seitenrnder
\renewcommand{\familydefault}{\sfdefault}
\usepackage{helvet}
\usepackage[left=4cm,right=3cm,top=3cm,bottom=3cm,includeheadfoot]{geometry}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\renewcommand{\headrulewidth}{0.5pt}

%Fu§zeile mittig
\fancyfoot[C]{\thepage}
%Linie unten
\renewcommand{\footrulewidth}{0.5pt}

%neue Rechtschreibung
\usepackage{ngerman}

\def\noun{%
{{Fu}},{{Fa}{ra}},{{U}{ta}},{{Ma}{ma}},%
{{Ma}{mi}},{{Ralf}},{{La}{ra}},%
{Ma}{ra},{{Mu}{rat}},{{Mar}{ta}},%
{{Ma}{mut}},{I}{ra},{Mi}{ra},{{Ma}{ri}{a}}%
}

\def\verb{{{malt}},{{ruft}},{{um}{armt}}%
}

\def\zc{\expandafter\zzblue}
\def\zzblue#1{%
\ifx\relax#1\else\textcolor{blue}{#1}%
\expandafter\zzred
\fi}

\def\zzred#1{%
\ifx\relax#1\else\textcolor{red}{#1}%
\expandafter\zzblue
\fi}

\begin{document}

\makeatletter


\@for\za:=\noun\do{%
\@for\zb:=\noun\do{%
\ifx\za\zb\else
\@for\v:=\verb\do{
\par\zc\za\relax\ \zc\v\relax\ \zc\zb\relax
\pgfmathparse{random(2)}%
\ifnum\pgfmathresult=1\ \textcolor{blue}{mit mir}\fi.

}%
\fi
}}

\end{document}


\pgfmathparse{random(8)}%
\let\zza\pgfmathresult

\pgfmathparse{random(8)}%
\show\pgfmathresult
  • 1
    VERY interesting problem. – Przemysław Scherwentke Sep 30 '14 at 15:15
  • It's a very lifelike problem, ie. nothing you'd find in a book ;) – Christian Oct 1 '14 at 6:56
12
+50
\documentclass{article}
\usepackage{pgfmath,color}
\def\noun{%
{{Fu}},{Fa}{ra},{{Uta}},{Ma}{ma},%
{Ma}{mi},{{Ralf}},{La}{ra},%
{Ma}{ra},{Mu}{rat},{Mar}{ta},%
{Ma}{mut},{Ir}{a},{Mir}{a},{Ma}{ri}{a}%
}

\def\verb{{{malt}},{{ruft}},{um}{armt}%
}

\def\zc{\expandafter\zzblue}
\def\zzblue#1{%
\ifx\relax#1\else\textcolor{blue}{#1}%
\expandafter\zzred
\fi}

\def\zzred#1{%
\ifx\relax#1\else\textcolor{red}{#1}%
\expandafter\zzblue
\fi}

\begin{document}

\makeatletter


\@for\za:=\noun\do{%
\@for\zb:=\noun\do{%
\ifx\za\zb\else
\@for\v:=\verb\do{
\par\zc\za\relax\ \zc\v\relax\ \zc\zb\relax
\pgfmathparse{random(2)}%
\ifnum\pgfmathresult=1\ \textcolor{blue}{mit mir}\fi.

}%
\fi
}}

\end{document}


\pgfmathparse{random(8)}%
\let\zza\pgfmathresult

\pgfmathparse{random(8)}%
\show\pgfmathresult
  • Shouldn't the line with \verb of your beautiful answer be \def\verb{{malt}{},{ruft}{},{um}{armt}%? Now it colours malt character by character... – Przemysław Scherwentke Sep 30 '14 at 18:47
  • @PrzemysławScherwentke oops yes you need to double brace single words as I did for {{Ralf}} (or an empty brace would work, but make an empty colour group) I'll fix, thanks – David Carlisle Sep 30 '14 at 19:47
  • @DavidCarlisle Amazing, great, fantastic, ... - if I could upvote by more then one I would certainly do so. Thank you! – Christian Oct 1 '14 at 6:41
  • I have added my current "setup" above (she can't read Serif fonts well yet and things need to be a little bigger with more linespacing) - would there be a way to randomize the lines? The current way of doing it (though perfect!) has n lines each start with the same noun, randomizing them would make the reading experience more interesting I suppose (plus - less guessing and more actual reading if I remember my Morse Code practice correctly (which, If I might say so, puts "learning to read" in a whole new perspective.)). – Christian Oct 1 '14 at 6:53
  • @Christian You'll note that I use pgfmath's random number generator already, for the extra text \pgfmathparse{random(10)} would leave a random integer between 1 and 10 in \pgfmathresult so easiest thing would be instead of the comma separated list, set things up as \@namedef{noun1}{David} \@namedef{noun2}{Christian}... then you could replace the nested loop by \pgfmathparse{random(10)}\edef\za{\@nameuse{noun\pgfmathresult}}\pgfmathparse{random(10)}\edef\zb{\@nameuse{noun\pgfmathresult}} to pick up two nouns – David Carlisle Oct 1 '14 at 11:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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