3

I'm trying to execute a macro that get a string as a parameter. I want to load the string from as a verbatim content of a file.

I'm oriented mostly on catchfile package with no success.

I've already seen

The file that I'm trying to import is full of different chars that could mislead so they should be interpreted as is. A small excerpt is (almost 10M of this stuff):

"@%$&DO\)9G}"-2"#""${@,}"11)+7${*^^}#1${*~}5)  ] ${*/&IIBs-2/v~1LAX}   $[   ((${@/+$Dw/R6k\{MQq:}-4"0"${!*}#"1"9-50"#"p)+${*,}29"#"4"h")   ] ${@//\[>2;^n}  ${!*} $(( (-(-(8#"1"61--"${@#Z\"2B53\{}"44#1$*E)+48#${*//OzmgVT%}2G))  ))  "${@##w\`$8}"   ${*%%om\[3W}  $(( (-(-(6#305--${@~}1"5"#${@//7ox@}2"c")+1${*,,}8"#""${@,,}"5${@%AVRW$,bC}6))   )) $@  $((  (-(-(3"7"#"p"*"${@/\]\`DcL\{/5g<yo}"50#${*,,}g)+30#b${*//vQN2uO~}b))   ))  ${@^}  $[   (-(-(1${*##\"hbv}1"${@//QVTk$}"#44+${@}43#"g")+4${@~}#11)) ] ${!*}  $((  ((34#o*"-"5${*#:\}imbKB}9#e)+"${@//t^Qyala/V1-=}"6"4"#6b)  ))  ${*,,}  $[  ((${*^}7#1$*0+4#21)+"3"4#${@#gxK5}o)  ]   ${*^^}   "${@//EoF$3/Euw\"#\)wl}" $(( ((${*~~}-5"7"#11+-${*#6UV>x6X}1${@/N\[ME}3#"c")+${@//X^F4Iz}3"1"#4c)   )) ${*^}   $[   (("3""#"202--4#13)+"4"5"#"w)   ] ${!*} ${*} $[ (-(-(34#n*"5"1${!*}#e)+14#14b)) ]   ${@,,} ${*/FGP\)Lf=}   $((  (("-"53#29+19#3${*#<&v\]}5)+${*~~}7"#""${@%%6&\"6?y6}"220)   )) ${@#67OE\}6}   "$@"   $((   ((-3#210+3"3"#"m")+2"${@,,}"6${@%=_FI?@T}#g) ))  "${@,}"  "${@~}"   $((  ((-1"2""#"1"8"-"-"59#10)+5#34)   )) ${@#WCeSRm} $(( ((-42#"${@#wPI&XRM}"1*23"#""0")+25#2)  ))   ${@/jKCyd/.5i0+\)z|}   $[   ((${*/7vBD*a}50#t--"4"#11)+"${@/$4HZ/wb5|\"N\};}"5"7"#m) ] ${*%%S2G0}  "${@//,uHr\`/h\`P93v1}"  $(( (-(-("$@"-1"9"#"1"0*-19${@/+\}J@#}#${@,,}c)+26${!@}#6g)) ))   "${@^}"  $((  ((-${*//i\=m~}19#c+64#b)+3#22)  )) ${*~}   ${!@} $((   ((${*^^}49#1G-${*#E;s;}1"5""#"2${*//We8#=^N+}7)+6${@/Fi2X0E4/.>:\}}4#a) )) ${@,} $((   ((-3"2"#v--"2"#1${*/TKD^2/\~=4@<}0${@~}0)+37#1n)  )) "${@~~}"   $[ ((20#"${@~}"e+2#100)+3${*~~}8"${@/Z7zg/n2u$O}"#1)   ]  ${@,,} $[   (-(-(7#${@,,}1"${@/PrCWYpAH/ICk|\(n}"1--${@}6"0"#k)+8#${@/nsJeW2}1"1")) ]  ${*%%4pEVH} ${*~~}   $((   ((59$@#A-3#12)+"2"4#${@^^}j)  ))  ${*,,}  ${!*}  $[   (-(-("${@//9h2775\]}"-4#12*-"4"#${@~~}1"0")+46#c))  ]   ${@/fw.Vf/|ao2V\`}   ${*%.@a<n}   $[  ((6${*}#"1""2"*"-"${@##UqN0}28#2)+51"#"13)  ] ${*/AJ\"W/WGu=}   $(( (-(-(6${*##@.IF}#${*##KDu\"}1--36#"u")+12#b))   ))  ${*#x1bN}   ${@~} $[  (-(-(${@~~}40${@^^}#${*^^}1c+5"4"#b)+"6"#13)) ]  ${@//~Ppe}   ${!@}   $[ (-(-("3"7#2"${@,,}"s-"-"$*14#2"d")+6#220))  ]   ${!@}   ${*~~}  $((   ((${*##_X\)oJY-}-17#"e"-${@//ES-w}1"2""#"${@//qxTm&/T=Pq@~l6}1"5")+3"9"${!@}#"2""c") )) ${*%%qvnCy_}   ${*~~}  $[  ((-3${@//\"vi9PxAA}9#r*40"#"g)+13#"2"ba)   ]   "${@%~|\[&\!}" ${@~~}   $[ ((23#"a"-${*~}2#"${@//JJgS/\)go~\)}"11)+"1"7"${@//RsGDY2sc}"#${*##&\`Q@_b}a)   ] ${@/lY\]\!D\(}   $((   ((-40#${!*}2f+"-"22${*,}#${*^}2"${@//xz\!\!lu}"3)+"5"9"$@"#3n)  ))   $*   $(( ((60${*#yulPQ}#1*${*~~}39#${*//zYWRJ/nQBHX~g}0)+${*,}54"#"2) ))   ${*//FNXb\"Cq/hdD;A*9\\}  $[  ((-6"4"${*~~}#1*43${*,,}#"0")+39#1d)   ] ${!*} $[ ((30#"1"6-${*#ZLe>\)d}6${*~}#"1"2)+3#100) ]  "${@/<tRzdd/_+j;\]x-\"}"   ${@^}   $(( (-(-(5#"1"${@//\[\oc\"*}1+3#$*22)+4"#"${@~~}1"${@^^}"2))  ))  ${*//SRToaWNl}  ${@%$\]PV2}   $[   ((-"6"0#e*11"#"12)+21"#"b1) ]  "${@~}"   ${@}  $((   ((-3"6""#""v"+15#${*^}31)+5"6"#q) )) ${@%%AS=MW^}  "${@//d+JA}" $((  (("-"29${*~}#15+23#3d)+2#100)  ))  ${*%\{A\{0M\"#n} $((  ((51"#"${*,}c*-"4"1"#"${*^^}a)+${*,,}55"#"2S) )) "${@~~}"  $

I need to apply some transform to each char what I've tried so far is

\documentclass{article}
\usepackage{catchfile}

\def\xloop#1{
  \ifx\relax#1
    \else
      \framebox[5ex]{
        \vrule height 2.5ex depth 1.5ex width 0pt\relax
          #1
      }\hskip0pt
      \expandafter\xloop
  \fi
}
\def\addbox#1{\xloop#1\relax}

\makeatletter
\CatchFileDef{\content}{test.sh}{\let\do\@makeother\dospecials\@noligs\obeyspaces\frenchspacing\relax}
\makeatother

\begin{document}
    \addbox\content
\end{document}
  • I wouldn't argue with latex here. I would rather look into lua to accomplish this. Classical file system I/O is not was latex was build for. – user1146332 Apr 13 at 20:36
3

Assuming your files are one liners, you can use expl3 to read them and to apply the loop.

\begin{filecontents*}{\jobname.txt}
"@%$&DO\)9G}"-2"#""${@,}"11)+7${*^^}#1${*~}5)  ] ${*/&IIBs-2/v~1LAX}   $[   ((${@/+$Dw/R6k\{MQq:}-4"0"${!*}#"1"9-50"#"p)+${*,}29"#"4"h")   ] ${@//\[>2;^n}  ${!*} $(( (-(-(8#"1"61--"${@#Z\"2B53\{}"44#1$*E)+48#${*//OzmgVT%}2G))  ))  "${@##w\`$8}"   ${*%%om\[3W}  $(( (-(-(6#305--${@~}1"5"#${@//7ox@}2"c")+1${*,,}8"#""${@,,}"5${@%AVRW$,bC}6))   )) $@  $((  (-(-(3"7"#"p"*"${@/\]\`DcL\{/5g<yo}"50#${*,,}g)+30#b${*//vQN2uO~}b))   ))  ${@^}  $[   (-(-(1${*##\"hbv}1"${@//QVTk$}"#44+${@}43#"g")+4${@~}#11)) ] ${!*}  $((  ((34#o*"-"5${*#:\}imbKB}9#e)+"${@//t^Qyala/V1-=}"6"4"#6b)  ))  ${*,,}  $[  ((${*^}7#1$*0+4#21)+"3"4#${@#gxK5}o)  ]   ${*^^}   "${@//EoF$3/Euw\"#\)wl}" $(( ((${*~~}-5"7"#11+-${*#6UV>x6X}1${@/N\[ME}3#"c")+${@//X^F4Iz}3"1"#4c)   )) ${*^}   $[   (("3""#"202--4#13)+"4"5"#"w)   ] ${!*} ${*} $[ (-(-(34#n*"5"1${!*}#e)+14#14b)) ]   ${@,,} ${*/FGP\)Lf=}   $((  (("-"53#29+19#3${*#<&v\]}5)+${*~~}7"#""${@%%6&\"6?y6}"220)   )) ${@#67OE\}6}   "$@"   $((   ((-3#210+3"3"#"m")+2"${@,,}"6${@%=_FI?@T}#g) ))  "${@,}"  "${@~}"   $((  ((-1"2""#"1"8"-"-"59#10)+5#34)   )) ${@#WCeSRm} $(( ((-42#"${@#wPI&XRM}"1*23"#""0")+25#2)  ))   ${@/jKCyd/.5i0+\)z|}   $[   ((${*/7vBD*a}50#t--"4"#11)+"${@/$4HZ/wb5|\"N\};}"5"7"#m) ] ${*%%S2G0}  "${@//,uHr\`/h\`P93v1}"  $(( (-(-("$@"-1"9"#"1"0*-19${@/+\}J@#}#${@,,}c)+26${!@}#6g)) ))   "${@^}"  $((  ((-${*//i\=m~}19#c+64#b)+3#22)  )) ${*~}   ${!@} $((   ((${*^^}49#1G-${*#E;s;}1"5""#"2${*//We8#=^N+}7)+6${@/Fi2X0E4/.>:\}}4#a) )) ${@,} $((   ((-3"2"#v--"2"#1${*/TKD^2/\~=4@<}0${@~}0)+37#1n)  )) "${@~~}"   $[ ((20#"${@~}"e+2#100)+3${*~~}8"${@/Z7zg/n2u$O}"#1)   ]  ${@,,} $[   (-(-(7#${@,,}1"${@/PrCWYpAH/ICk|\(n}"1--${@}6"0"#k)+8#${@/nsJeW2}1"1")) ]  ${*%%4pEVH} ${*~~}   $((   ((59$@#A-3#12)+"2"4#${@^^}j)  ))  ${*,,}  ${!*}  $[   (-(-("${@//9h2775\]}"-4#12*-"4"#${@~~}1"0")+46#c))  ]   ${@/fw.Vf/|ao2V\`}   ${*%.@a<n}   $[  ((6${*}#"1""2"*"-"${@##UqN0}28#2)+51"#"13)  ] ${*/AJ\"W/WGu=}   $(( (-(-(6${*##@.IF}#${*##KDu\"}1--36#"u")+12#b))   ))  ${*#x1bN}   ${@~} $[  (-(-(${@~~}40${@^^}#${*^^}1c+5"4"#b)+"6"#13)) ]  ${@//~Ppe}   ${!@}   $[ (-(-("3"7#2"${@,,}"s-"-"$*14#2"d")+6#220))  ]   ${!@}   ${*~~}  $((   ((${*##_X\)oJY-}-17#"e"-${@//ES-w}1"2""#"${@//qxTm&/T=Pq@~l6}1"5")+3"9"${!@}#"2""c") )) ${*%%qvnCy_}   ${*~~}  $[  ((-3${@//\"vi9PxAA}9#r*40"#"g)+13#"2"ba)   ]   "${@%~|\[&\!}" ${@~~}   $[ ((23#"a"-${*~}2#"${@//JJgS/\)go~\)}"11)+"1"7"${@//RsGDY2sc}"#${*##&\`Q@_b}a)   ] ${@/lY\]\!D\(}   $((   ((-40#${!*}2f+"-"22${*,}#${*^}2"${@//xz\!\!lu}"3)+"5"9"$@"#3n)  ))   $*   $(( ((60${*#yulPQ}#1*${*~~}39#${*//zYWRJ/nQBHX~g}0)+${*,}54"#"2) ))   ${*//FNXb\"Cq/hdD;A*9\\}  $[  ((-6"4"${*~~}#1*43${*,,}#"0")+39#1d)   ] ${!*} $[ ((30#"1"6-${*#ZLe>\)d}6${*~}#"1"2)+3#100) ]  "${@/<tRzdd/_+j;\]x-\"}"   ${@^}   $(( (-(-(5#"1"${@//\[\oc\"*}1+3#$*22)+4"#"${@~~}1"${@^^}"2))  ))  ${*//SRToaWNl}  ${@%$\]PV2}   $[   ((-"6"0#e*11"#"12)+21"#"b1) ]  "${@~}"   ${@}  $((   ((-3"6""#""v"+15#${*^}31)+5"6"#q) )) ${@%%AS=MW^}  "${@//d+JA}" $((  (("-"29${*~}#15+23#3d)+2#100)  ))  ${*%\{A\{0M\"#n} $((  ((51"#"${*,}c*-"4"1"#"${*^^}a)+${*,,}55"#"2S) )) "${@~~}"  $
\end{filecontents*}

\documentclass{article}
\usepackage{xparse}

\ExplSyntaxOn

\ior_new:N \g_pna_getfile_ior
\str_new:N \l_pna_getfile_str

\NewDocumentCommand{\getfile}{mm}
 {% #1 = file name, #2 = loop macro
  \ior_open:Nn \g_pna_getfile_ior { #1 }
  \ior_str_get:NN \g_pna_getfile_ior \l_pna_getfile_str
  \str_map_function:NN \l_pna_getfile_str#2
  \ior_close:N \g_pna_getfile_ior
}

\ExplSyntaxOff

\newcommand{\loopfbox}[1]{%
  \framebox[5ex]{%
    \rule[-1.5ex]{0pt}{4ex}%
    #1%
  }\hspace{0pt}%
}


\begin{document}

\begin{flushleft}
\getfile{\jobname.txt}{\loopfbox}
\end{flushleft}

\end{document}

enter image description here

As you see, multiple spaces are preserved.

| improve this answer | |

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.