아치 위키에서처럼 코드 조각 위에 파일 이름을 표시하는 방법은 무엇입니까?

아치 위키에서처럼 코드 조각 위에 파일 이름을 표시하는 방법은 무엇입니까?

문맥

저는 LaTeX로 특정 Linux 기반 장치를 만드는 방법에 대한 튜토리얼과 같은 문서를 작성하고 있습니다. 장치를 다시 만드는 노력의 일부는 Bash 또는 Python으로 작은 코드 조각을 작성하고 구성 파일을 편집하는 것입니다.

이 모든 내용이 문서에 포함되어야 합니다. 다시 만들려면 파일 이름과 파일 내용을 알아야 합니다. 나는 아치맨들이 하는 방식을 좋아한다.위키, 깨끗하고 간단합니다.

[아치 위키][1]의 일부

예를 들어, "/etc/systemd/system/unit.d/customexec.conf"는 파일 이름이고 아래 세 줄은 파일의 실제 텍스트입니다.

마지막으로 코드의 구문이 강조 표시되기를 원합니다. 나는 사용한다주조된그에 대한. 나는 또한 줄 번호를 갖는 것을 중요하게 생각합니다. 이를 참조하면 훨씬 더 쉬워집니다.

내가 지금 가지고 있는 것

나는 인터넷에서 찾은 몇 가지 예와 작성된 문서를 가지고 놀았습니다. 그래도 나는 아직도 내가 가진 것이 마음에 들지 않습니다. MWE는 다음과 같습니다.

\documentclass{report}

\usepackage[table,usenames,dvipsnames,hyperref]{xcolor}
\usepackage{listings}
\usepackage{caption}

\DeclareCaptionStyle{mystyle}%
[margin=2mm,justification=raggedright]%
{font=footnotesize,labelfont=sc,margin={100mm,10mm}}

\DeclareCaptionFormat{continued}{File#2#3}

\captionsetup{style=mystyle, indention=10cm, format=continued}

\usepackage[newfloat]{minted}
\SetupFloatingEnvironment{listing}{name=File}

\definecolor{mintedbackground}{rgb}{0.95,0.95,0.95}

% This is the bash profile used throughout the document.
% I've also got one for Python and console text (regular commands)
\newminted[bashcode]{bash}{
    bgcolor=mintedbackground,
    fontfamily=tt,
    linenos=true,
    numberblanklines=true,
    numbersep=12pt,
    numbersep=5pt,
    gobble=0,
    frame=leftline,
    framesep=2mm,
    funcnamehighlighting=true,
    tabsize=4,
    obeytabs=false,
    mathescape=false
    samepage=false,
    showspaces=false,
    showtabs =false,
    texcl=false,
    baselinestretch=1.2,
    fontsize=\footnotesize,
    breaklines=true,
}

\begin{document}

\begin{listing}[H]
\caption{/files/location/on/system.sh}
\begin{bashcode}
#!/bin/bash
echo "I am a bash file"
\end{bashcode}
\end{listing}

\end{document}

다음을 출력합니다(원본 출력의 컷아웃).

위의 MWE 결과

MWE에서 볼 수 있듯이 캡션을 파일 이름으로 잘못 사용하고 있습니다. 전반적으로 마음에 들지는 않지만 캡션이 민트 섹션의 범위를 벗어나기 때문에 캡션 부분을 민트 배경으로 깔끔하게 만드는 것도 불가능하다고 생각합니다.

메모:MWE에는 minted 2가 필요합니다. 내 배포판(Kubuntu 14.04)은 이전 버전과 함께 제공됩니다. .sty 파일을 여기에서 다운로드했습니다: https://raw.githubusercontent.com/gpoore/minted/master/source/minted.sty (죄송합니다. 두 개 이상의 링크를 포함할 포인트가 충분하지 않습니다).

질문

간단히 말해서, 아치 위키 예제에 어떻게 접근할 수 있습니까?

나는 민트를 사용하지 않는 솔루션으로 괜찮습니다. 솔루션이 보기에 좋을 필요도 없습니다. 나는 지금 외부 HTML 파일에 이러한 조각을 생성한 다음 이를 포함하려고 생각하고 있습니다. 실행 가능한 한 괜찮습니다. 문서는 몇 주 안에 완료되고 계속 작업할 필요가 없으므로 모든 것을 자동화하고 통합하는 것은 그다지 중요하지 않습니다.

미리 감사드립니다! 일부 정보를 포함하지 못한 경우 알려 주시기 바랍니다.

답변1

tcolorbox패키지를 사용하여 목록을 구성 할 수 있습니다 . 와 함께 작동할 수 있습니다 minted. 다음은 귀하의 스타일에 맞게 사용자 정의된 다소 기본 출력입니다 minted.

\documentclass{report}

\usepackage[skins,minted]{tcolorbox}

\definecolor{mintedbackground}{rgb}{0.95,0.95,0.95}

% This is the bash profile used throughout the document.
% I've also got one for Python and console text (regular commands)
\setminted[bash]{
    bgcolor=mintedbackground,
    fontfamily=tt,
    linenos=true,
    numberblanklines=true,
    numbersep=12pt,
    numbersep=5pt,
    gobble=0,
    frame=leftline,
    framesep=2mm,
    funcnamehighlighting=true,
    tabsize=4,
    obeytabs=false,
    mathescape=false
    samepage=false,
    showspaces=false,
    showtabs =false,
    texcl=false,
    baselinestretch=1.2,
    fontsize=\footnotesize,
    breaklines=true,
}

\newtcblisting{myminted}[2][]{listing engine=minted, listing only,#1, title=#2, minted language=bash, colback=mintedbackground}
\begin{document}

\begin{myminted}{/files/location/on/system.sh}
#!/bin/bash
echo "I am a bash file"
\end{myminted}

\end{document}

여기에 이미지 설명을 입력하세요

일부 색상 및 크기 조정이 누락되었지만 결과는 OP가 제안한 상자와 더 유사합니다.

여기에 이미지 설명을 입력하세요

\documentclass{report}

\usepackage[skins,minted]{tcolorbox}

\definecolor{mintedbackground}{rgb}{0.95,0.95,0.95}
\definecolor{mintedframe}{rgb}{0.70,0.85,0.95}

% This is the bash profile used throughout the document.
% I've also got one for Python and console text (regular commands)
\setminted[bash]{
    bgcolor=mintedbackground,
    fontfamily=tt,
    linenos=true,
    numberblanklines=true,
    numbersep=12pt,
    numbersep=5pt,
    gobble=0,
    frame=leftline,
    framesep=2mm,
    funcnamehighlighting=true,
    tabsize=4,
    obeytabs=false,
    mathescape=false
    samepage=false,
    showspaces=false,
    showtabs =false,
    texcl=false,
    baselinestretch=1.2,
    fontsize=\footnotesize,
    breaklines=true,
}

\newtcblisting{myminted}[2][]{enhanced, listing engine=minted, 
listing only,#1, title=#2, minted language=bash, 
coltitle=mintedbackground!30!black, 
fonttitle=\ttfamily\footnotesize,
sharp corners, top=0mm, bottom=0mm,
title code={\path[draw=mintedframe,dashed, fill=mintedbackground](title.south west)--(title.south east);},
frame code={\path[draw=mintedframe, fill=mintedbackground](frame.south west) rectangle (frame.north east);}
}
\begin{document}

\begin{myminted}{/files/location/on/system.sh}
#!/bin/bash
echo "I am a bash file"
\end{myminted}

\end{document}

답변2

이 답변은 Ignasi의 초기 게시물을 기반으로 합니다. 나는 그가 이미 내가 필요로 하는 답변을 정확히 편집했는지 확인하기 위해 그것을 다듬기 시작했습니다. 그래도 가치가 있고 누군가가 그로부터 혜택을 받기를 바라면서 지금까지의 접근 방식은 다음과 같습니다. 하지만 저장소에 texlive와 함께 제공되는 버전보다 최신 버전의 tcolorbox가 필요합니다.

이것이 그의 첫 번째 예제를 작업한 후 제가 생각해낸 것입니다.

\documentclass{report}

\usepackage[skins,minted]{tcolorbox}

\definecolor{mintedbackground}{rgb}{0.95,0.95,0.95}

% This is the bash profile used throughout the document.
% I've also got one for Python and console text (regular commands)
\setminted[bash]{
    bgcolor=mintedbackground,
    fontfamily=tt,
    linenos=true,
    numberblanklines=true,
    numbersep=12pt,
    numbersep=5pt,
    gobble=0,
    frame=leftline,
    framesep=2mm,
    funcnamehighlighting=true,
    tabsize=4,
    obeytabs=false,
    mathescape=false
    samepage=false,
    showspaces=false,
    showtabs =false,
    texcl=false,
    baselinestretch=1.2,
    fontsize=\footnotesize,
    breaklines=true,
}

\newtcblisting{myminted}[2][]{minted language=bash,
    enhanced, listing engine=minted,
    listing only, #1, title=#2, 
    colback=mintedbackground, colbacktitle=mintedbackground, coltitle=darkgray, 
    arc=0pt,outer arc=0pt, 
    boxrule=0mm, 
    toptitle=1mm, bottomtitle=1mm,
    titlerule=1pt, colframe=gray, titlerule style={mintedbackground, dashed}    
}

\begin{document}

\begin{myminted}{/files/location/on/system.sh}
    #!/bin/bash
    echo "I am a bash file"
\end{myminted}

\end{document}

다음을 제공합니다.

여기에 이미지 설명을 입력하세요

답변3

Ignasi의 답변이 나에게 적합하지 않았습니다. 정의 minted options={python3} 내부에 추가하는 것이 \newtcblisting나에게 도움이 되었습니다.

답변4

다른 패키지를 사용하여 답변을 허용하면 개인적으로 사용하고 있습니다listings좋은 효과를 위해서.

\documentclass{report}

\usepackage{listings}

\begin{document}

\begin{lstlisting}[title=/files/location/on/system.sh,language=bash,numbers=left]
#!/bin/bash
echo "I am a bash file"
\end{listing}

\end{document}

아직 시도하지 않았습니다 minted. 나는 listingsa) 내가 사용하고 있는 도메인별 언어에 대한 구문 강조 표시, b) 사용자 정의 강조 표시를 사용하여 코드의 특정 부분을 다르게 렌더링하는 것이 얼마나 쉬운지 좋아했습니다 . 렌더링/스타일 옵션도 많습니다.

관련 정보