我的标签如下:
\documentclass[]{book}
\usepackage{textcomp}
\usepackage{listings}
\usepackage{MnSymbol}%
\usepackage[many]{tcolorbox}
\tcbuselibrary{listings,breakable}
\makeatletter
\lstdefinestyle{mypyscriptstyle}{%
upquote=true,
language=Python,
basicstyle=\ttfamily\fontsize{10}{14}\selectfont,
commentstyle=\tt\fontsize{10}{14}\selectfont, %
stringstyle=\ttfamily\slshape\fontsize{10}{14}\selectfont,%
showspaces=false,
showtabs=false,
showstringspaces=false,
columns=fixed,%%
breaklines=true,xleftmargin=4\p@,xrightmargin=0\p@,aboveskip=0\p@,belowskip=0\p@,
postbreak=\raisebox{0ex}[0ex][0ex]{\ensuremath{\rcurvearrowse\space}},
morecomment=[s]{"""}{"""},
morecomment=[s]{'''}{'''},
morecomment=[l]{\#},
keywordstyle=\bfseries,
keywords={},
sensitive=true,
string=[b]',
morestring=[b]",
escapechar={§},
alsoletter={_, .},
emphstyle=\color{black}\bfseries,
emph={assert, break, class, continue, def, del, elif, else, except, finally, for, global, help, in, lambda, not, or, pass, raise, return, try, while, with, yield, exec, Ellipsis, None, NotImplemented, ArithmeticError, AssertionError, AttributeError, EnvironmentError, EOFError, Exception, FloatingPointError, ImportError, IndentationError, IndexError, IOError, KeyboardInterrupt, KeyError, LookupError, MemoryError, NameError, NotImplementedError, OSError, OverflowError, ReferenceError, RuntimeError, StandardError, StopIteration, SyntaxError, SystemError, SystemExit, TabError, TypeError, UnboundLocalError, UnicodeDecodeError, UnicodeEncodeError, UnicodeError, UnicodeTranslateError, ValueError, WindowsError, ZeroDivisionError, Warning, UserWarning, DeprecationWarning, PendingDeprecationWarning, SyntaxWarning, OverflowWarning, RuntimeWarning, FutureWarning, abs, any, bin, bool, callable, chr, classmethod, compile, complex, delattr, dict, dir, divmod, enumerate, eval, filter, float, format, frozenset, getattr, globals, hasattr, hash, hex, id, input, int, isinstance, issubclass, iter, len, list, locals, map, max, min, object, oct, open, ord, pow, property, range, repr, reversed, round, setattr, set, slice, sorted, staticmethod, str, sum, super, tuple, type, vars, zip, apply, basestring, buffer, cmp, coerce, execfile, file, intern, long, , reduce, reload, unichr, unicode, xrange, import, __import__, print, match, search, readline, rstrip, group, VERBOSE, finditer, findall,
join, upper, lower, replace, find, count, strip, split, append, copy, clear, index, pop, sort, reverse, get, items, keys, values, update, intersection, union, symmetric_difference, difference, issubset, issuperset, if, name, mode, encoding, write, writelines, close, as, seek, whos, deepcopy, start, end, dimension, shape, ndim, size, mean, std, sqrt, exp, array, zeros, ones, arange, reshape, random, loadtxt, re, who, from, imread, imshow, loc, iloc, drop, median, hist, email, esearch, efetch, parse, description, id, seq, alignments, read, }
}
\newtcblisting{testcode}{before skip=12pt, after skip=14.5pt,top=7.5\p@,bottom=8\p@,boxsep=0\p@,breakable,colback=black!6,left=7pt,right=9.5pt,arc=0pt,leftrule=0pt,rightrule=0pt,toprule=0pt,bottomrule=0pt,arc=0pt,listing
options={style=mypyscriptstyle,xleftmargin=4pt},listing only }
\makeatother
\begin{document}
\begin{testcode}
f.§§write(s + "\n") # write string s and go to a new line
f.§§writelines(["A\n", "B\n", "C\n"]) # write multiple strings provided as a list
\end{testcode}%
\end{document}
它运行良好,但我需要在整个过程中获得罗马字体的斜线字符,如屏幕截图中所示:
这可能吗?请提出建议...
答案1
您可以使用该literate
选项自动执行此操作。
\documentclass[]{book}
\usepackage{textcomp}
\usepackage{listings}
\usepackage{MnSymbol}
\usepackage[many]{tcolorbox}
\tcbuselibrary{listings,breakable}
\lstdefinestyle{mypyscriptstyle}{
upquote=true,
language=Python,
basicstyle=\fontsize{10}{14}\ttfamily,
commentstyle=\fontsize{10}{14}\normalfont\ttfamily,
stringstyle=\fontsize{10}{14}\normalfont\ttfamily\slshape,
showspaces=false,
showtabs=false,
showstringspaces=false,
columns=fixed,
breaklines=true,
xleftmargin=4pt,
xrightmargin=0pt,
aboveskip=0pt,
belowskip=0pt,
postbreak=\raisebox{0ex}[0ex][0ex]{\ensuremath{\rcurvearrowse\space}},
morecomment=[s]{"""}{"""},
morecomment=[s]{'''}{'''},
morecomment=[l]{\#},
keywordstyle=\bfseries,
keywords={},
sensitive=true,
string=[b]',
morestring=[b]",
escapechar={§},
alsoletter={_, .},
emphstyle=\color{black}\bfseries,
literate={\\}{{\upshape\textbackslash}}1,
emph={assert, break, class, continue, def, del, elif, else, except, finally, for, global, help, in, lambda, not, or, pass, raise, return, try, while, with, yield, exec, Ellipsis, None, NotImplemented, ArithmeticError, AssertionError, AttributeError, EnvironmentError, EOFError, Exception, FloatingPointError, ImportError, IndentationError, IndexError, IOError, KeyboardInterrupt, KeyError, LookupError, MemoryError, NameError, NotImplementedError, OSError, OverflowError, ReferenceError, RuntimeError, StandardError, StopIteration, SyntaxError, SystemError, SystemExit, TabError, TypeError, UnboundLocalError, UnicodeDecodeError, UnicodeEncodeError, UnicodeError, UnicodeTranslateError, ValueError, WindowsError, ZeroDivisionError, Warning, UserWarning, DeprecationWarning, PendingDeprecationWarning, SyntaxWarning, OverflowWarning, RuntimeWarning, FutureWarning, abs, any, bin, bool, callable, chr, classmethod, compile, complex, delattr, dict, dir, divmod, enumerate, eval, filter, float, format, frozenset, getattr, globals, hasattr, hash, hex, id, input, int, isinstance, issubclass, iter, len, list, locals, map, max, min, object, oct, open, ord, pow, property, range, repr, reversed, round, setattr, set, slice, sorted, staticmethod, str, sum, super, tuple, type, vars, zip, apply, basestring, buffer, cmp, coerce, execfile, file, intern, long, , reduce, reload, unichr, unicode, xrange, import, __import__, print, match, search, readline, rstrip, group, VERBOSE, finditer, findall,
join, upper, lower, replace, find, count, strip, split, append, copy, clear, index, pop, sort, reverse, get, items, keys, values, update, intersection, union, symmetric_difference, difference, issubset, issuperset, if, name, mode, encoding, write, writelines, close, as, seek, whos, deepcopy, start, end, dimension, shape, ndim, size, mean, std, sqrt, exp, array, zeros, ones, arange, reshape, random, loadtxt, re, who, from, imread, imshow, loc, iloc, drop, median, hist, email, esearch, efetch, parse, description, id, seq, alignments, read, }
}
\newtcblisting{testcode}{
before skip=12pt,
after skip=14.5pt,
top=7.5pt,
bottom=8pt,
boxsep=0pt,
breakable,
colback=black!6,
left=7pt,
right=9.5pt,
arc=0pt,
leftrule=0pt,
rightrule=0pt,
toprule=0pt,
bottomrule=0pt,
arc=0pt,
listing options={style=mypyscriptstyle,xleftmargin=4pt},listing only
}
\begin{document}
\begin{testcode}
f.§§write(s + "\n") # write string s and go to a new line
f.§§writelines(["A\n", "B\n", "C\n"]) # write multiple strings provided as a list
\end{testcode}
\end{document}