我正在尝试执行一个获取字符串作为参数的宏。我想将字符串作为文件的逐字内容加载。
我主要关注catchfile
包装,但没有成功。
我已经看到了
- 如何将外部存储的链接文本添加到超链接中?
- https://stackoverflow.com/questions/414191/using-verbatim-as-part-of-an-argument-for-a-macro
- 如何创建一个宏,当定义宏时,该宏可以读取文件的内容?
我尝试导入的文件充满了各种可能产生误导的字符,因此应按原样进行解释。以下是一小段摘录(这些内容几乎有 10M):
"@%$&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) )) "${@~~}" $
我需要对每个字符应用一些变换,到目前为止我尝试过的是
\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}
答案1
假设您的文件只有一行,您可以用expl3
它读取它们并应用循环。
\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}
如您所见,多个空格被保留了。