在 beamer 框架中为 minted 环境设置字体

在 beamer 框架中为 minted 环境设置字体

我在将 beamer 框架中的 minted 环境的字体设置为我想要的特定字体时遇到了问题。我希望该区域采用 Inconsolata(或者至少采用带有斜线穿过 0(零)的等宽字体)

\documentclass{beamer}
\usepackage{minted}
\usepackage{inconsolata}
\definecolor{bg}{rgb}{0.5,0.5,0.5}
\begin{document}
\begin{frame}[fragile]
\frametitle{Example}
0123456789
\begin{minted}[frame=lines,linenos=true,gobble=2]{html}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" 
"http://www.w3.org/TR/html4/strict.dtd">
<html>
 <head>
  <meta http-equiv="Content-Type" 
    content="text/html; charset=UTF-8">
  <meta http-equiv="Content-Language" 
    content="en-us">
   <title>Our first web page!</title>
 </head>
 <body>
  <p>Hello World!</p>
 </body>
</html>
\end{minted}
\end{frame}
\end{document}

这可以编译,但不会为铸造区域设置字体。救命!(而且背景颜色似乎没有设置……)

这是我得到的输出。

 $ pdflatex -shell-escape foo.tex               4:55PM
 This is pdfTeX, Version 3.1415926-1.40.10 (TeX Live 2009/Debian)
  \write18 enabled.
 entering extended mode
 (./foo.tex
 LaTeX2e <2009/09/24>
 Babel <v3.8l> and hyphenation patterns for english, usenglishmax, dumylang, noh
 yphenation, farsi, arabic, croatian, bulgarian, ukrainian, russian, czech, slov
 ak, danish, dutch, finnish, french, basque, ngerman, german, german-x-2009-06-1
 9, ngerman-x-2009-06-19, ibycus, monogreek, greek, ancientgreek, hungarian, san
 skrit, italian, latin, latvian, lithuanian, mongolian2a, mongolian, bokmal, nyn
 orsk, romanian, irish, coptic, serbian, turkish, welsh, esperanto, uppersorbian
 , estonian, indonesian, interlingua, icelandic, kurmanji, slovenian, polish, po
 rtuguese, spanish, galician, catalan, swedish, ukenglish, pinyin, loaded.
 (/usr/share/texmf/tex/latex/beamer/base/beamer.cls
 (/usr/share/texmf/tex/latex/beamer/base/beamerbasercs.sty)
 Document Class: beamer 2010/06/21 development version 3.10 A class for typesett
 ing presentations (rcs-revision a6b1a8434d30)
 (/usr/share/texmf/tex/latex/beamer/base/beamerbasemodes.sty
 (/usr/share/texmf/tex/latex/beamer/base/beamerbasedecode.sty))
 (/usr/share/texmf/tex/latex/beamer/base/beamerbaseoptions.sty
 (/usr/share/texmf-texlive/tex/latex/graphics/keyval.sty))
 (/usr/share/texmf-texlive/tex/latex/geometry/geometry.sty
 (/usr/share/texmf-texlive/tex/generic/oberdiek/ifpdf.sty)
 (/usr/share/texmf-texlive/tex/generic/oberdiek/ifvtex.sty)
 (/usr/share/texmf-texlive/tex/xelatex/xetexconfig/geometry.cfg))
 (/usr/share/texmf-texlive/tex/latex/base/size11.clo)
 (/usr/share/texmf/tex/latex/pgf/basiclayer/pgfcore.sty
 (/usr/share/texmf-texlive/tex/latex/graphics/graphicx.sty
 (/usr/share/texmf-texlive/tex/latex/graphics/graphics.sty
 (/usr/share/texmf-texlive/tex/latex/graphics/trig.sty)
 (/etc/texmf/tex/latex/config/graphics.cfg)
 (/usr/share/texmf-texlive/tex/latex/pdftex-def/pdftex.def)))
 (/usr/share/texmf/tex/latex/pgf/systemlayer/pgfsys.sty
 (/usr/share/texmf/tex/latex/pgf/utilities/pgfrcs.sty
 (/usr/share/texmf/tex/generic/pgf/utilities/pgfutil-common.tex)
 (/usr/share/texmf/tex/generic/pgf/utilities/pgfutil-latex.def
 (/usr/share/texmf-texlive/tex/latex/ms/everyshi.sty))
 (/usr/share/texmf/tex/generic/pgf/utilities/pgfrcs.code.tex))
 (/usr/share/texmf/tex/generic/pgf/systemlayer/pgfsys.code.tex
 (/usr/share/texmf/tex/generic/pgf/utilities/pgfkeys.code.tex
 (/usr/share/texmf/tex/generic/pgf/utilities/pgfkeysfiltered.code.tex))
 (/usr/share/texmf/tex/generic/pgf/systemlayer/pgf.cfg)
 (/usr/share/texmf/tex/generic/pgf/systemlayer/pgfsys-pdftex.def
 (/usr/share/texmf/tex/generic/pgf/systemlayer/pgfsys-common-pdf.def)))
 (/usr/share/texmf/tex/generic/pgf/systemlayer/pgfsyssoftpath.code.tex)
 (/usr/share/texmf/tex/generic/pgf/systemlayer/pgfsysprotocol.code.tex))
 (/usr/share/texmf/tex/latex/xcolor/xcolor.sty
 (/etc/texmf/tex/latex/config/color.cfg))
 (/usr/share/texmf/tex/generic/pgf/basiclayer/pgfcore.code.tex
 (/usr/share/texmf/tex/generic/pgf/math/pgfmath.code.tex
 (/usr/share/texmf/tex/generic/pgf/math/pgfmathcalc.code.tex
 (/usr/share/texmf/tex/generic/pgf/math/pgfmathutil.code.tex)
 (/usr/share/texmf/tex/generic/pgf/math/pgfmathparser.code.tex)
 (/usr/share/texmf/tex/generic/pgf/math/pgfmathfunctions.code.tex
 (/usr/share/texmf/tex/generic/pgf/math/pgfmathfunctions.basic.code.tex)
 (/usr/share/texmf/tex/generic/pgf/math/pgfmathfunctions.trigonometric.code.tex)
 (/usr/share/texmf/tex/generic/pgf/math/pgfmathfunctions.random.code.tex)
 (/usr/share/texmf/tex/generic/pgf/math/pgfmathfunctions.comparison.code.tex)
 (/usr/share/texmf/tex/generic/pgf/math/pgfmathfunctions.base.code.tex)
 (/usr/share/texmf/tex/generic/pgf/math/pgfmathfunctions.round.code.tex)
 (/usr/share/texmf/tex/generic/pgf/math/pgfmathfunctions.misc.code.tex)))
 (/usr/share/texmf/tex/generic/pgf/math/pgfmathfloat.code.tex))
 (/usr/share/texmf/tex/generic/pgf/basiclayer/pgfcorepoints.code.tex)
 (/usr/share/texmf/tex/generic/pgf/basiclayer/pgfcorepathconstruct.code.tex)
 (/usr/share/texmf/tex/generic/pgf/basiclayer/pgfcorepathusage.code.tex)
 (/usr/share/texmf/tex/generic/pgf/basiclayer/pgfcorescopes.code.tex)
 (/usr/share/texmf/tex/generic/pgf/basiclayer/pgfcoregraphicstate.code.tex)
 (/usr/share/texmf/tex/generic/pgf/basiclayer/pgfcoretransformations.code.tex)
 (/usr/share/texmf/tex/generic/pgf/basiclayer/pgfcorequick.code.tex)
 (/usr/share/texmf/tex/generic/pgf/basiclayer/pgfcoreobjects.code.tex)
 (/usr/share/texmf/tex/generic/pgf/basiclayer/pgfcorepathprocessing.code.tex)
 (/usr/share/texmf/tex/generic/pgf/basiclayer/pgfcorearrows.code.tex)
 (/usr/share/texmf/tex/generic/pgf/basiclayer/pgfcoreshade.code.tex)
 (/usr/share/texmf/tex/generic/pgf/basiclayer/pgfcoreimage.code.tex
 (/usr/share/texmf/tex/generic/pgf/basiclayer/pgfcoreexternal.code.tex))
 (/usr/share/texmf/tex/generic/pgf/basiclayer/pgfcorelayers.code.tex)
 (/usr/share/texmf/tex/generic/pgf/basiclayer/pgfcoretransparency.code.tex)
 (/usr/share/texmf/tex/generic/pgf/basiclayer/pgfcorepatterns.code.tex)))
 (/usr/share/texmf/tex/latex/pgf/utilities/xxcolor.sty)
 (/usr/share/texmf-texlive/tex/latex/hyperref/hyperref.sty
 (/usr/share/texmf-texlive/tex/generic/ifxetex/ifxetex.sty)
 (/usr/share/texmf-texlive/tex/latex/oberdiek/hycolor.sty
 (/usr/share/texmf-texlive/tex/latex/oberdiek/xcolor-patch.sty))
 (/usr/share/texmf-texlive/tex/latex/hyperref/pd1enc.def)
 (/usr/share/texmf-texlive/tex/*emphasized text*generic/oberdiek/etexcmds.sty
 (/usr/share/texmf-texlive/tex/generic/oberdiek/infwarerr.sty))
 (/usr/share/texmf-texlive/tex/latex/latexconfig/hyperref.cfg)
 (/usr/share/texmf-texlive/tex/latex/oberdiek/kvoptions.sty
 (/usr/share/texmf-texlive/tex/generic/oberdiek/kvsetkeys.sty))
 Implicit mode OFF; no redefinition of LaTeX internals
 (/usr/share/texmf-texlive/tex/latex/ltxmisc/url.sty)
 (/usr/share/texmf-texlive/tex/generic/oberdiek/bitset.sty
 (/usr/share/texmf-texlive/tex/generic/oberdiek/intcalc.sty)
 (/usr/share/texmf-texlive/tex/generic/oberdiek/bigintcalc.sty
 (/usr/share/texmf-texlive/tex/generic/oberdiek/pdftexcmds.sty
 (/usr/share/texmf-texlive/tex/generic/oberdiek/ifluatex.sty)
 (/usr/share/texmf-texlive/tex/generic/oberdiek/ltxcmds.sty))))
 (/usr/share/texmf-texlive/tex/generic/oberdiek/atbegshi.sty)
 Hyperref stopped early
 )
 *hyperref using default driver hpdftex*
 (/usr/share/texmf-texlive/tex/latex/hyperref/hpdftex.def)
 (/usr/share/texmf/tex/latex/beamer/base/beamerbaserequires.sty
 (/usr/share/texmf/tex/latex/beamer/base/beamerbasecompatibility.sty)
 (/usr/share/texmf/tex/latex/beamer/base/beamerbasefont.sty
 (/usr/share/texmf-texlive/tex/latex/amsfonts/amssymb.sty
 (/usr/share/texmf-texlive/tex/latex/amsfonts/amsfonts.sty)))
 (/usr/share/texmf/tex/latex/beamer/base/beamerbasetranslator.sty
 (/usr/share/texmf/tex/latex/beamer/base/translator/translator.sty
 (/usr/share/texmf/tex/latex/beamer/base/translator/translator-language-mappings
 .tex))) (/usr/share/texmf/tex/latex/beamer/base/beamerbasemisc.sty)
 (/usr/share/texmf/tex/latex/beamer/base/beamerbasetwoscreens.sty)
 (/usr/share/texmf/tex/latex/beamer/base/beamerbaseoverlay.sty)
 (/usr/share/texmf/tex/latex/beamer/base/beamerbasetitle.sty)
 (/usr/share/texmf/tex/latex/beamer/base/beamerbasesection.sty)
 (/usr/share/texmf/tex/latex/beamer/base/beamerbaseframe.sty)
 (/usr/share/texmf/tex/latex/beamer/base/beamerbaseverbatim.sty)
 (/usr/share/texmf/tex/latex/beamer/base/beamerbaseframesize.sty)
 (/usr/share/texmf/tex/latex/beamer/base/beamerbaseframecomponents.sty)
 (/usr/share/texmf/tex/latex/beamer/base/beamerbasecolor.sty)
 (/usr/share/texmf/tex/latex/beamer/base/beamerbasenotes.sty)
 (/usr/share/texmf/tex/latex/beamer/base/beamerbasetoc.sty)
 (/usr/share/texmf/tex/latex/beamer/base/beamerbasetemplates.sty
 (/usr/share/texmf/tex/latex/beamer/base/beamerbaseauxtemplates.sty
 (/usr/share/texmf/tex/latex/beamer/base/beamerbaseboxes.sty)))
 (/usr/share/texmf/tex/latex/beamer/base/beamerbaselocalstructure.sty
 (/usr/share/texmf-texlive/tex/latex/tools/enumerate.sty))
 (/usr/share/texmf/tex/latex/beamer/base/beamerbasenavigation.sty)
 (/usr/share/texmf/tex/latex/beamer/base/beamerbasetheorems.sty
 (/usr/share/texmf-texlive/tex/latex/amsmath/amsmath.sty
 For additional information on amsmath, use the `?' option.
 (/usr/share/texmf-texlive/tex/latex/amsmath/amstext.sty
 (/usr/share/texmf-texlive/tex/latex/amsmath/amsgen.sty))
 (/usr/share/texmf-texlive/tex/latex/amsmath/amsbsy.sty)
 (/usr/share/texmf-texlive/tex/latex/amsmath/amsopn.sty))
 (/usr/share/texmf-texlive/tex/latex/amscls/amsthm.sty))
 (/usr/share/texmf/tex/latex/beamer/base/beamerbasethemes.sty))
 (/usr/share/texmf/tex/latex/beamer/base/themes/theme/beamerthemedefault.sty
 (/usr/share/texmf/tex/latex/beamer/base/themes/font/beamerfontthemedefault.sty)

 (/usr/share/texmf/tex/latex/beamer/base/themes/color/beamercolorthemedefault.st
 y)
 (/usr/share/texmf/tex/latex/beamer/base/themes/inner/beamerinnerthemedefault.st
 y)
 (/usr/share/texmf/tex/latex/beamer/base/themes/outer/beamerouterthemedefault.st
 y))) (/home/dkerschner/texmf/tex/latex/minted/minted.sty
 (/usr/share/texmf-texlive/tex/latex/fancyvrb/fancyvrb.sty
 Style option: `fancyvrb' v2.7a, with DG/SPQR fixes, and firstline=lastline fix 
 <2008/02/07> (tvz)) (/usr/share/texmf-texlive/tex/latex/float/float.sty)
 (/usr/share/texmf-texlive/tex/latex/base/ifthen.sty)
 (/usr/share/texmf-texlive/tex/latex/tools/calc.sty)
 (/usr/share/texmf-texlive/tex/latex/ifplatform/ifplatform.sty
 (/usr/share/texmf-texlive/tex/generic/oberdiek/catchfile.sty) (./foo.w18)))/usr/bin/pygmentize

 (/usr/share/texmf-texlive/tex/latex/inconsolata/inconsolata.sty
 (/usr/share/texmf-texlive/tex/latex/base/textcomp.sty
 (/usr/share/texmf-texlive/tex/latex/base/ts1enc.def))) (./foo.aux)
 (/usr/share/texmf-texlive/tex/latex/base/ts1cmr.fd)
 *geometry auto-detecting driver*
 *geometry detected driver: pdftex*
 (/usr/share/texmf-texlive/tex/context/base/supp-pdf.mkii
 [Loading MPS to PDF converter (version 2006.09.02).]
 ) ABD: EveryShipout initializing macros
 (/usr/share/texmf-texlive/tex/latex/hyperref/nameref.sty
 (/usr/share/texmf-texlive/tex/latex/oberdiek/refcount.sty)) (./foo.out)
 (./foo.out)
 (/usr/share/texmf/tex/latex/beamer/base/translator/dicts/translator-basic-dicti
 onary/translator-basic-dictionary-English.dict)
 (/usr/share/texmf/tex/latex/beamer/base/translator/dicts/translator-bibliograph
 y-dictionary/translator-bibliography-dictionary-English.dict)
 (/usr/share/texmf/tex/latex/beamer/base/translator/dicts/translator-environment
 -dictionary/translator-environment-dictionary-English.dict)
 (/usr/share/texmf/tex/latex/beamer/base/translator/dicts/translator-months-dict
 ionary/translator-months-dictionary-English.dict)
 (/usr/share/texmf/tex/latex/beamer/base/translator/dicts/translator-numbers-dic
 tionary/translator-numbers-dictionary-English.dict)
 (/usr/share/texmf/tex/latex/beamer/base/translator/dicts/translator-theorem-dic
 tionary/translator-theorem-dictionary-English.dict) (./foo.pyg) (./foo.nav)
 (./foo.vrb (./foo.out.pyg
 (/usr/share/texmf-texlive/tex/latex/inconsolata/ot1fi4.fd)

 LaTeX Font Warning: Font shape `OT1/fi4/m/it' undefined
 (Font)              using `OT1/fi4/m/n' instead on input line 2.


 LaTeX Font Warning: Font shape `OT1/fi4/bx/n' undefined
 (Font)              using `OT1/fi4/m/n' instead on input line 4.

 ))

 LaTeX Font Warning: Font shape `OT1/cmss/m/n' in size <4> not available
 (Font)              size <5> substituted on input line 25.

 [1{/var/lib/texmf/fonts/map/pdftex/updmap/pdftex.map}] (./foo.aux)

 LaTeX Font Warning: Size substitutions with differences
 (Font)              up to 1.0pt have occurred.


 LaTeX Font Warning: Some font shapes were not available, defaults substituted.

  )
 (see the transcript file for additional information){/usr/share/texmf-texlive/f
 onts/enc/dvips/inconsolata/fi4-ot1tt.enc}</usr/share/texmf-texlive/fonts/type1/
 public/inconsolata/Inconsolata.pfb></usr/share/texmf-texlive/fonts/type1/public
 /amsfonts/cm/cmr6.pfb></usr/share/texmf-texlive/fonts/type1/public/amsfonts/cm/
 cmss10.pfb></usr/share/texmf-texlive/fonts/type1/public/amsfonts/cm/cmss12.pfb>

 Output written on foo.pdf (1 page, 42698 bytes).
 Transcript written on foo.log.

答案1

根据 inconsolata 手册,\usepackage[nott]{inconsolata}不会将tt字体更改为 inconsolata,但您仍然可以通过 使用它\fontfamily{fi4}\selectfont。这样,您就可以在您的minted环境中使用它fontfamily=fi4

inconsolata 手册显示虚线零我有一个位于T1编码表216位置的符号,但我不知道如何使用它。

消失的问题<可能是因为gobble=2它删除了每行的前 2 个字符。因此,您需要在 minted 环境中将所有行缩进至少 2 个字符。(查看第二个示例)

背景颜色的问题已经解决了更改 Beamer 中框架的背景颜色。我在下一个代码中包含了解决方案,第一个 minted 示例不使用 inconsolata,而第二个使用了。

\documentclass{beamer}
\usepackage{minted}
\usepackage[nott]{inconsolata}
\definecolor{mycolor}{rgb}{0.5,0.5,0.5}
\begin{document}
\setbeamercolor{background canvas}{bg=mycolor!30}
\begin{frame}[fragile]{}
\begin{minted}[frame=lines,linenos=true,gobble=2]{html}
  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" 
       "http://www.w3.org/TR/html4/strict.dtd">
  <html>
  <head>
    <meta http-equiv="Content-Type" 
     content="text/html; charset=UTF-8">
\end{minted}

\begin{minted}[frame=lines,linenos=true,gobble=2,fontfamily=fi4]{html}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" 
    "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" 
   content="text/html; charset=UTF-8">
<meta http-equiv="Content-Language" 
\end{minted}
\end{frame}
\end{document}

在此处输入图片描述

答案2

所以我设法让它做我想做的事,但是仅使用 XeLaTeX,Inconsolata 包中似乎存在一个错误,其中 0 不是字体的标准 0。

\documentclass{beamer}

\usepackage{minted}
\usepackage{fontspec}

\setmonofont{Inconsolata}

\begin{document}
\begin{frame}[fragile]
\frametitle{Example}
0123456789
\begin{minted}[frame=lines,linenos=true,gobble=2]{html}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">
<html>
   <head>
      <meta http-equiv="Content-Type"
        content="text/html; charset=UTF-8">
      <meta http-equiv="Content-Language"
      content="en-us">
      <title>Our first web page!</title>
  </head>
  <body>
    <p>Hello World!</p>
  </body>
</html>
\end{minted}
\end{frame}
\end{document}

相关内容