Below is a perl subroutine to escape latex special characters. This is useful for printing SMILES notation of the compounds.
sub latex_escape
{
my $paragraph = shift;
# Replace a \ with $\backslash$
# This is made more complicated because the dollars will be escaped
# by the subsequent replacement. Easiest to add \backslash
# now and then add the dollars
$paragraph =~ s/\\/\\backslash/g;
# Must be done after escape of \ since this command adds latex escapes
# Replace characters that can be escaped
$paragraph =~ s/([\$\#&%_{}])/\\$1/g;
# Replace ^ characters with \^{} so that $^F works okay
$paragraph =~ s/(\^)/\\$1\{\}/g;
# Replace tilde (~) with \texttt{\~{}}
$paragraph =~ s/~/\\texttt\{\\~\{\}\}/g;
# Now add the dollars around each \backslash
$paragraph =~ s/(\\backslash)/\$$1\$/g;
return $paragraph;
}
Credit for perl subroutine: http://www.mail-archive.com/templates@template-toolkit.org/msg07971.html
Here is list of Latex special characters (Source: http://happymutant.com/latex/latex2.html)
special characters
Since certain characters are used in LaTeX commands (e.g., the backslash and curly braces), if you want to actually print these characters in your document, there are special commands that tell LaTeX to print these characters (not to treat them as part of a command). Here are some of those characters, along with the commands to print them:| character | command |
| \ | $\backslash$ |
| $ | \$ |
| % | \% |
| ^ | \^ |
| & | \& |
| _ | \_ |
| ~ | \~ |
| # | \ |
| { | $\{$ |
| } | $\}$ |
| £ | \pounds |
No comments:
Post a Comment