使用 Metapost 圖形使用精美的頁碼

使用 Metapost 圖形使用精美的頁碼

ConTeXt是一種很棒的 TeX 格式,特別是因為Metapost它緊密整合到其中,可以產生像這樣的頁碼樣式

在此輸入影像描述

它很容易實現如果你知道Metapost(我承認我不知道,但正在學習)。以下是從文件中複製並貼上的程式碼來源產生了這種頁碼樣式。

\setuppapersize[A4][A4]
\setuplayout[topspace=0.5in, backspace=1in, header=24pt, footer=36pt,
  height=middle, width=middle]

\def\MPclipFive#1#2#3#4%
  {\startreusableMPgraphic{clip:five:#1#2#3#4}{}
     %
     delta  := #4;
     width  := #1-delta;
     height := #2-delta;
     lines  := #3;
     %
     z1 = (0,0);
     z2 = (lines,0);
     z3 = (.5width,height);
     z4 = (width-lines,0);
     z5 = (width,0);
     %
     pickup pencircle
       xscaled delta
       yscaled .5delta
       rotated 30;
     %
     draw z1--z2{dir 135}...z3...{dir -135}z4--z5 withcolor (.5,.5,.5);
     %
     pickup pencircle
       scaled delta;
     %
     draw z1 withcolor red;
     draw z2 withcolor red;
     draw z3 withcolor red;
     draw z4 withcolor red;
     draw z5 withcolor red;
     %
   \stopreusableMPgraphic
   \reuseMPgraphic{clip:five:#1#2#3#4}{}}

\defineoverlay
  [NummerAchtergrond]
  [\MPclipFive{\overlaywidth}{\overlayheight}{30pt}{5pt}]

\setuppagenumbering
  [\c!location={\v!footer,\v!middle},
   \c!command=\NummerCommando]

\unexpanded\def\NummerCommando#1%
  {\framed
     [\c!background=NummerAchtergrond,
      \c!frame=\v!off,
      \c!offset=6pt]
     {\lower.5\dp\strutbox\hbox spread 60pt{\hss#1\hss}}}

%\setuppagenumbering[location={footer,center}]

\setupbodyfont[11pt,palatino]

\setupindenting[medium,yes]

\starttext
\phantom{Text.}
\vfill
\midaligned{Text.}
\stoptext

雖然我很喜歡用 來處理其他事情ConTeXt,但我擔心我的技能無法與我的 LaTeX 經驗相媲美,無法完成我通常做的一些排版,特別是數學和tikz圖形方面的排版。值得慶幸的是,人們可以Metapost在 LaTeX 中使用gmp包裹。我已經成功地將egreg的範例用於精美的標題,但由於我認為缺乏對如何和工作gmp原理的理解,我無法計算出頁碼的詳細資訊。我正在考慮使用圖形整合來達到效果。這是一個可以玩的。\sbox\mpdimfancyhdrMetapostMWE

\documentclass[10pt]{article}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[shellescape,tex]{gmp}
\usepackage{xcolor}

\usepackage{titlesec}

\def\MPclipOne#1#2#3#4#5{\begin{mpost}
      w := #1;  width  := 100;  wfactor := w/width;
      h := #2;  height := 100;  hfactor := h/height;
      color lightred;  lightred  := (.90,.50,.50);
      color lightgray; lightgray := (.95,.95,.95);
      color gray;      gray      := (.50,.50,.50);
      def random_delta (expr d) =
        d-(uniformdeviate 2d)
      enddef;
      z1 = (0,height);
      z2 = (0,0);
      z3 = (width,0);
      z4 = (width,height);
      z5 = (width+random_delta(.2width),height+random_delta(.2height));
      z6 = (.5width+random_delta(.1width),height+random_delta(.1height));
      pickup pencircle
        xscaled (#3/wfactor)
        yscaled (#3/(2*hfactor))
        rotated 30;
      draw z5..z1..z2..z3..z4..z6 withcolor #4;
      pickup pencircle
        xscaled (#3/wfactor)
        yscaled (#3/hfactor);
      draw z1 withcolor #5;
      draw z2 withcolor #5;
      draw z3 withcolor #5;
      draw z4 withcolor #5;
      draw z5 withcolor #5;
      draw z6 withcolor #5;
      newwidth  := (xpart (urcorner currentpicture)) -
                   (xpart (llcorner currentpicture));
      newheight := (ypart (urcorner currentpicture)) -
                   (ypart (llcorner currentpicture));
      currentpicture := currentpicture
       xscaled (w/newwidth) yscaled (h/newheight);
    \end{mpost}}

\def\MPclipFive#1#2#3#4%
  {\begin{mpost}
     %
     delta  := #4;
     width  := #1-delta;
     height := #2-delta;
     lines  := #3;
     %
     z1 = (0,0);
     z2 = (lines,0);
     z3 = (.5width,height);
     z4 = (width-lines,0);
     z5 = (width,0);
     %
     pickup pencircle
       xscaled delta
       yscaled .5delta
       rotated 30;
     %
     draw z1--z2{dir 135}...z3...{dir -135}z4--z5 withcolor (.5,.5,.5);
     %
     pickup pencircle
       scaled delta;
     %
     draw z1 withcolor red;
     draw z2 withcolor red;
     draw z3 withcolor red;
     draw z4 withcolor red;
     draw z5 withcolor red;
     %
   \end{mpost}}

% I want to combine this with fancyhdr, perhaps, to get the desired result.

\newsavebox{\tacopage}
\newcommand{\tacopagenumber}[1]{%
\sbox\tacopage{#1}%
{\ooalign{%
\MPclipFive{\mpdim{\wd\tacopage}} % width
{\mpdim{\ht\tacopage}} % height
{12}
% thickness of the curve
{(.7,.7,.7)}
% color of the curve
{red}
% color of the spots
\cr\hfill
%\raisebox{\dimexpr.15\ht\tacopage+1.5pc\relax}
{\box\tacopage}\hfill
}}}

% For the section formatting

\newsavebox{\tacochapterbox}
\newcommand{\tacochapterhead}[1]{%
\sbox\tacochapterbox{\Large\bfseries #1}%
{\ooalign{%
\MPclipOne{\mpdim{\wd\tacochapterbox+6pc}} % width
{\mpdim{\ht\tacochapterbox+3pc}} % height
{8}
% thickness of the curve
{(.7,.7,.7)}
% color of the curve
{red}
% color of the spots
\cr\hfill\raisebox{\dimexpr.5\ht\tacochapterbox+1.5pc\relax}
{\box\tacochapterbox}\hfill}}}

\newcommand{\secformat}[1]{\tacochapterhead{\thesection\ \raisebox{-4pt}{\textcolor{green}{\rule{1pt}{\baselineskip}}}\ #1}}
\titleformat{name=\section}[block]
{\large\bfseries\filcenter}{}{0pt}{\secformat}
\titleformat{name=\section,numberless}[block]
{\large\bfseries\filcenter}{}{0pt}{\tacochapterhead}

\begin{document}


%\maketitle
\section{A section}

\tacopagenumber{a try}

\end{document}

產生輸出:

在此輸入影像描述

相關內容