<div dir="ltr"><div><br></div><div>>
\catcode`\~=12% <br></div><div><br></div><div>changing catcodes in an environment looks wrong (the % after the 12 is definitely wrong) if you change catcodes then the definition cannot work in the argument of any command (for the same reasons that \verb does not work in command arguments) . Leave ~ active but make it expand to the inactive one eg</div><div><br></div><div>\edef~{\string~}%</div><div><br></div><div><br></div></div>