Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have not learnt how the TeX expansion works behind the scene. Shortly speaking, how to write \StrGobbleLeft output to an external file?

\documentclass{article}
\usepackage{filecontents}
\begin{filecontents*}{rawdata.txt}
beamerthemeAnnArbor.sty
beamerthemeAntibes.sty
beamerthemeBergen.sty
beamerthemeBerkeley.sty
beamerthemeBerlin.sty
beamerthemeBoadilla.sty
beamerthemeboxes.sty
beamerthemeCambridgeUS.sty
beamerthemeCopenhagen.sty
beamerthemeDarmstadt.sty
beamerthemedefault.sty
beamerthemeDresden.sty
beamerthemeEastLansing.sty
beamerthemeFrankfurt.sty
beamerthemeGoettingen.sty
beamerthemeHannover.sty
beamerthemeIlmenau.sty
beamerthemeJuanLesPins.sty
beamerthemeLuebeck.sty
beamerthemeMadrid.sty
beamerthemeMalmoe.sty
beamerthemeMarburg.sty
beamerthemeMontpellier.sty
beamerthemePaloAlto.sty
beamerthemePittsburgh.sty
beamerthemeRochester.sty
beamerthemeSingapore.sty
beamerthemeSzeged.sty
beamerthemeWarsaw.sty
beamerthemebars.sty
beamerthemeclassic.sty
beamerthemecompatibility.sty
beamerthemelined.sty
beamerthemeplain.sty
beamerthemeshadow.sty
beamerthemesidebar.sty
beamerthemesplit.sty
beamerthemetree.sty
\end{filecontents*}

\usepackage{xstring}

\begin{document}
% writer
\newwrite\writer
\immediate\openout\writer=list.txt\relax
% reader
\newread\reader
\openin\reader=rawdata.txt\relax
\makeatletter
\loop
    \read\reader to \x
    \unless\ifeof\reader
        \filename@parse{\x}
        \immediate\write\writer{\StrGobbleLeft{\filename@base}{11}}
\repeat
\makeatother
\closein\reader
\immediate\closeout\writer
\end{document}
share|improve this question
add comment

2 Answers 2

up vote 5 down vote accepted

\StrGobbleLeft is not expandable, therefore it will not work inside \write. But the package xstring is so kind to provide an optional argument at the end. If present, it takes a macro name that stores the result.

\StrGobbleLeft{\filename@base}{11}[\Result]
\immediate\write\writer{\Result}
share|improve this answer
add comment

You need an a macro that works via expansion if you want to place it in the write for example:

\documentclass{article}
\usepackage{filecontents}
\begin{filecontents*}{rawdata.txt}
beamerthemeAnnArbor.sty
beamerthemeAntibes.sty
beamerthemeBergen.sty
beamerthemeBerkeley.sty
beamerthemeBerlin.sty
beamerthemeBoadilla.sty
beamerthemeboxes.sty
beamerthemeCambridgeUS.sty
beamerthemeCopenhagen.sty
beamerthemeDarmstadt.sty
beamerthemedefault.sty
beamerthemeDresden.sty
beamerthemeEastLansing.sty
beamerthemeFrankfurt.sty
beamerthemeGoettingen.sty
beamerthemeHannover.sty
beamerthemeIlmenau.sty
beamerthemeJuanLesPins.sty
beamerthemeLuebeck.sty
beamerthemeMadrid.sty
beamerthemeMalmoe.sty
beamerthemeMarburg.sty
beamerthemeMontpellier.sty
beamerthemePaloAlto.sty
beamerthemePittsburgh.sty
beamerthemeRochester.sty
beamerthemeSingapore.sty
beamerthemeSzeged.sty
beamerthemeWarsaw.sty
beamerthemebars.sty
beamerthemeclassic.sty
beamerthemecompatibility.sty
beamerthemelined.sty
beamerthemeplain.sty
beamerthemeshadow.sty
beamerthemesidebar.sty
beamerthemesplit.sty
beamerthemetree.sty
\end{filecontents*}

\usepackage{xstring}

\begin{document}
% writer
\newwrite\writer
\immediate\openout\writer=list.txt\relax
% reader
\newread\reader
\openin\reader=rawdata.txt\relax
\makeatletter
\loop
    \read\reader to \x
    \unless\ifeof\reader
        \filename@parse{\x}%
        \def\zaptheme beamertheme{}%
        \immediate\write\writer{\expandafter\zaptheme \filename@base}
\repeat
\makeatother
\closein\reader
\immediate\closeout\writer
\end{document}
share|improve this answer
    
Thanks for the trick without using xstring. I will use your answer in my production. –  Please don't touch Aug 20 '12 at 22:16
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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