# How to output a repetitive string on console using typeout

I'm trying to create an easy macro to trace - on the console - the source files of my input. In first intention, I want to create a new command called "TraceHere" that will output the current filename (it works nicely with embedded sources, I had a try) between two lines of asterisks, as clear delimiters.

I created a command "RepeatAst" to output a line of asterisks. My issue is that I can't call it within "typeout" since I'm getting it's definition in the output.

Here is the minimal code, directly compilable I think.

\documentclass{article}

\usepackage{lipsum}
\usepackage[realmainfile]{currfile}

\newcount\TraceHereStar
\newcommand{\RepeatAst}{\TraceHereStar0\loop\ifnum\TraceHereStar < 25 $\ast$\advance\TraceHereStar by 1\repeat}

\newcounter{TraceHereCount}
\setcounter{TraceHereCount}{1}
% forcer les notes toujours à gauche
\newcommand{\TraceHere}{\typeout{^^J\RepeatAst^^J\arabic{TraceHereCount} *** Source file: \currfilepath^^J\RepeatAst^^J}\stepcounter{TraceHereCount}}

\begin{document}

\TraceHere
\lipsum[1-4]
\newpage
\TraceHere
\lipsum[5-7]

\end{document}


And here is an exemple of output

\TraceHereStar 0\def \iterate {$\ast$\advance \TraceHereStar by 1\relax \itera
te }\iterate \let \iterate \relax
1 *** Source file: test.tex
\TraceHereStar 0\def \iterate {$\ast$\advance \TraceHereStar by 1\relax \itera
te }\iterate \let \iterate \relax


Can someone explain me why the command "RepeatAst" is listed instead of its expected result (and what correction do I need to implement)? Thanks in advance.

• \typeout expands its argument, but the assignments within your loop prevent expansion – user31729 Aug 6 '16 at 9:12

In my opinion \typeout can't work here due to fact that it expands the argument and there are two assignments inside (actually 26 here!) which prevent expansion.

• \TraceHereStar0 is an assignment
• \advance\TraceHereStar by 1 is an assignment too

In addition $\ast$ has no meaning for the console and is unexpandable there!

A possible workaround is to 'fill' \RepeatAst before it is used in the \TraceHere macro.

\documentclass{article}

\usepackage{lipsum}
\usepackage[realmainfile]{currfile}

\newcount\TraceHereStar

\newcommand{\PrepareRepeatAst}{%
\TraceHereStar0
\def\RepeatAst{}
\loop\ifnum\TraceHereStar < 25
\xdef\RepeatAst{\RepeatAst *}
\repeat
}

\PrepareRepeatAst
\newcounter{TraceHereCount}
\setcounter{TraceHereCount}{1}

% forcer les notes toujours à gauche
\newcommand{\TraceHere}{\typeout{^^J\RepeatAst^^J\arabic{TraceHereCount} *** Source file: \currfilepath^^J\RepeatAst^^J}\stepcounter{TraceHereCount}}

\begin{document}

\TraceHere
\lipsum[1-4]
\newpage
\TraceHere
\lipsum[5-7]

\end{document}


Here is the output:

Package currfile-abspath Warning: The required recorder file (.fls) was not fou
nd.
(currfile-abspath)                Please compile with the '-recorder' option.
(currfile-abspath)                Note that MikTeX requires two compiler runs.
(currfile-abspath)                Occurred on input line 292.

) (./repeat.aux)

*************************
1 *** Source file: repeat.tex
*************************

[1{/usr/local/texlive/2016/texmf-var/fonts/map/pdftex/updmap/pdftex.map}]

*************************
2 *** Source file: repeat.tex
*************************

• With expl3 one can do \tl_const:Nx \c_detienne_repeatast_tl { \prg_replicate:nn { 25 } { * } }`. – Manuel Aug 6 '16 at 11:16
• I just tested the revision of my code with your "\PrepareRepeatAst" and it works exactly as I wanted. Thanks for your help! – Eric Detienne Aug 6 '16 at 12:11
• @EricDetienne: If this answer fits your requests, consider to accept it please – user31729 Aug 6 '16 at 20:05