
minted
배경색으로 구문 색상을 얻으려면 패키지를 사용합니다 . 나는 그것이 프린터에 매우 비우호적이라는 것을 알고 있지만 그것을 사용합니다.
내 목표는 배경 사각형 색상이 울 페이지 너비를 갖도록 만드는 것입니다. 그러나 포함된 코드는 일반 여백 안에 있어야 합니다.
따라서 다음 MWE를 사용하면 다음과 같습니다.
\documentclass[a4paper]{article}
\usepackage{minted,xcolor}
\usemintedstyle{monokai}
\definecolor{bg}{HTML}{282828} % from https://github.com/kevinsawicki/monokai
\begin{document}
{Code Example:}
\begin{minted}[bgcolor=bg,
frame=lines,
framesep=2mm]{python}
#!/usr/bin/env python2
def example_function():
return "hello world"
a = 5
b = "I am python code"
\end{minted}
\end{document}
다음 렌더링을 얻고 싶습니다.
tcolorbox
and 로 만들려고 하는데 adjustbox
텍스트의 여백이 유지되지 않습니다.
그렇다면 이 렌더링을 어떻게 얻을 수 있습니까?
편집하다 :
MWE를 다음과 같이 수정합니다.
\documentclass[11pt,letterpaper]{article}
\usepackage[breakable]{tcolorbox}
\usepackage{minted,xcolor}
\usepackage{xcolor,eso-pic}
\usepackage[savepos]{zref}
\usepackage{color}
\usepackage{lipsum}
\definecolor{bg}{HTML}{282828} % from https://github.com/kevinsawicki/monokai
\newenvironment{widthcode}%
{%
\begin{tcolorbox}[breakable,size=tight,oversize,
sharp corners,
colback=blue,
left=150pt,
right=150pt,
]}%
{%
\end{tcolorbox}
}
\setminted[text]{breaklines}
\setminted{bgcolor=bg,
linenos,
breaklines,
fontsize=\footnotesize}
\begin{document}
\begin{minted}{python}
#!/usr/bin/env python2
def example_function():
return "hello world"
a = 5
b = "I am python code"
\end{minted}
\lipsum[2]
\begin{minted}{sh}
#!/bin/sh
# Simple line count example, using sh
#
# sh tutorial: http://linuxconfig.org/Bash_scripting_Tutorial#8-2-read-file-into-bash-array
# My scripting link: http://www.macs.hw.ac.uk/~hwloidl/docs/index.html#scripting
#
# Usage: ./line_count.sh file
# -----------------------------------------------------------------------------
# Link filedescriptor 10 with stdin
exec 10<&0
# stdin replaced with a file supplied as a first argument
exec < $1
# remember the name of the input file
in=$1
# init
file="current_line.txt"
let count=0
# this while loop iterates over all lines of the file
while read LINE
do
# increase line counter
((count++))
# write current line to a tmp file with name $file (not needed for counting)
echo $LINE > $file
# this checks the return code of echo (not needed for writing; just for demo)
if [ $? -ne 0 ]
then echo "Error in writing to file ${file}; check its permissions!"
fi
done
echo "Number of lines: $count"
echo "The last line of the file is: `cat ${file}`"
# Note: You can achieve the same by just using the tool wc like this
echo "Expected number of lines: `wc -l $in`"
# restore stdin from filedescriptor 10
# and close filedescriptor 10
exec 0<&10 10<&-
mkvmerge --machin-chouette
\end{minted}
\lipsum[2]
\lipsum[2-4]
\begin{widthcode}
\begin{minted}{sh}
#!/bin/sh
# Simple line count example, using sh
#
# sh tutorial: http://linuxconfig.org/Bash_scripting_Tutorial#8-2-read-file-into-bash-array
# My scripting link: http://www.macs.hw.ac.uk/~hwloidl/docs/index.html#scripting
#
# Usage: ./line_count.sh file
# -----------------------------------------------------------------------------
# Link filedescriptor 10 with stdin
exec 10<&0
# stdin replaced with a file supplied as a first argument
exec < $1
# remember the name of the input file
in=$1
# init
file="current_line.txt"
let count=0
# this while loop iterates over all lines of the file
while read LINE
do
# increase line counter
((count++))
# write current line to a tmp file with name $file (not needed for counting)
echo $LINE > $file
# this checks the return code of echo (not needed for writing; just for demo)
if [ $? -ne 0 ]
then echo "Error in writing to file ${file}; check its permissions!"
fi
done
echo "Number of lines: $count"
echo "The last line of the file is: `cat ${file}`"
# Note: You can achieve the same by just using the tool wc like this
echo "Expected number of lines: `wc -l $in`"
# restore stdin from filedescriptor 10
# and close filedescriptor 10
exec 0<&10 10<&-
mkvmerge --machin-chouette
\end{minted}
\end{widthcode}
\end{document}
보시다시피 저는 widthcode
페이지 왼쪽에서 오른쪽으로 큰 파란색 배경을 배치하는 환경을 만듭니다. 이것은 widthcode
잘 작동하며 긴 텍스트에 대해 페이지 나누기를 허용합니다.
minted
그러나 환경을 하나에 넣으면 widthcode
실패합니다.
그래서 질문은 다음과 같습니다.환경 minted
에서 환경을 깨뜨릴 수 있게 만드는 방법은 무엇입니까 ?tcolorbox