Make soul and texttt work together

Make soul and texttt work together



I was trying to redefine texttt command to make it have background color using package soul. But it seems that it is harder than I thought.


texttt



My initial code is


documentclassarticle
usepackagexcolor, soul
colorletmycolorred!30
sethlcolormycolor

letoldtexttttexttt
renewcommandtexttt[1]
hloldtexttt#1


begindocument

textttcan we highlight

enddocument



But it won't run, the error message is:



Argument of texttt has an extra }.



I searched and found this post. The post suggests to use soulregister command. So I add the following line before begindocument:


soulregister


begindocument


soulregistertexttt1



But the error persists. I also found this post, which further suggests to use DeclareRobustCommand. Now my code is


DeclareRobustCommand


documentclassarticle
usepackagexcolor, soul
colorletmycolorred!30
sethlcolormycolor

letoldtexttttexttt
% renewcommandtexttt[1]
% hloldtexttt#1
%

DeclareRobustCommandtexttt[1]
hloldtexttt#1

soulregistertexttt1

begindocument

textttcan we highlight

enddocument



But it doesn't work. The error message is



TeX capacity exceeded, sorry [grouping levels=255]



It seems like rabbit hole of issues. Can you point out what has gone wrong? How to fix this seemingly simple problem?



Edit:



I am using Pandoc to convert Markdown file to PDF. The underlying LaTeX command for Markdown inline code is texttt. But there is no background color. That is why I want to combine soul and texttt.


texttt


texttt



I have tried the solution of @egreg and @daleif. They both work for standard alone tex code.


documentclassarticle
usepackagexcolor, soul

colorletmycolorred!30
sethlcolormycolor

letoldtexttttexttt

% renewcommandtexttt[1]
% ttfamilyhl#1
%

DeclareRobustCommandtexttt[1]%
hlttfamily#1%


begindocument

textttcan we highlight

enddocument



But if I put it in a file head.tex and compile Markdown to PDF, there are still errors. The content of head.tex is:


head.tex


head.tex


usepackagexcolor, soul

colorletmycolorred!30
sethlcolormycolor

letoldtexttttexttt
DeclareRobustCommandtexttt[1]%
hlttfamily#1%



Content of test.md is


test.md


`some inline words`



If I try to generate PDF using the new header:


pandoc -H head.tex -s test.md -o test.pdf



there occurs another error:



Package soul Error: Reconstruction failed.




2 Answers
2



The soul macros are rather special, it works on a macro level this cannot handle that the contents has "macros" in it.


soul



I would not overload texttt like that, make a special macro for it.


texttt



BTW: This works ttfamilyhl#1


ttfamilyhl#1



The working of texttt is essentially absorbing its argument and issuing ttfamily.


texttt


ttfamily


documentclassarticle
usepackagexcolor, soul

colorletmycolorred!30
sethlcolormycolor

DeclareRobustCommandtexttt[1]%
hlttfamily#1%


begindocument

textttcan we highlight

enddocument



enter image description here



On the other hand, it would be better to use a different command:


documentclassarticle
usepackagexcolor, soul

colorletmycolorred!30
sethlcolormycolor

DeclareRobustCommandhltt[1]%
hlttfamily#1%


begindocument

hlttcan we highlight

enddocument



Don't forget to protect the end-of-lines.



Thanks for contributing an answer to TeX - LaTeX Stack Exchange!



But avoid



To learn more, see our tips on writing great answers.



Some of your past answers have not been well-received, and you're in danger of being blocked from answering.



Please pay close attention to the following guidance:



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)