在 moderncv 中引入礼貌折叠标记

在 moderncv 中引入礼貌折叠标记

我有一个新想法,但似乎不知道如何实现……一如既往!

我正在做一些实验moderncv,我想引入像scrlttr2(KOMA 2 信函格式)那样的折叠标记 - 可能只在求职信上,而不是在简历页面上。

我做了以下事情:我moderncv在本地软件包存储库中创建了一个副本(在 Mac 上使用 MacTex:)~/Library/textmf/tex/latex并对其进行了注册(使用sudo texhash)。

由于我不熟悉超出正常用法的(有时)复杂的 LaTeX 命令,因此我认真地将所有命令从scrlttr2.cls以单词“fold”为特色复制到我的副本的开头moderncv.cls,就在\ProvidesClass{moderncv}表达式之后(第 13 行)。然后我尝试编译我的moderncv模板副本,由于缺少我粘贴的代码所需的一些表达式而出现一些错误。我在中识别了这些表达式,scrlttr2.cls并将它们也复制到我的副本中moderncv.cls。我重复了几次这个过程,直到我卡住了。我添加的代码如下:

\RequirePackage{keyval}
\newcommand*{\KOMA@key}{\define@key{KOMA}}
\newif\if@fold\@foldtrue
\KOMA@key{foldmarks}[true]{\@setif[@fold]{foldmarks}{#1}}
\newcommand*{\foldmarkson}{%
  \@ObsoleteCommand{\foldmarkson}{foldmarks=on}}
\newcommand*{\foldmarksoff}{%
  \@ObsoleteCommand{\foldmarksoff}{foldmarks=off}}
\newcommand*{\@newplength}[1]{%
  \@ifundefined{ltr@len@#1}{%
    \expandafter\let\csname ltr@len@#1\endcsname=\z@%
    }{%
    \ClassError{scrlttr2}{%
      pseudo-length \expandafter\string\csname ltr@len@#1\endcsname
      already defined%
      }{%
      You tried to define a new pseudo-length using
      \string\@newplength\MessageBreak
      which is already defined. Try another name or
      better\MessageBreak
      Don't use this KOMA-Script internal macro}
    }
  }
\@newplength{foldmarkhpos}
\@newplength{tfoldmarkvpos}
\@newplength{bfoldmarkvpos}
\newcommand*{\@foldmark}[2]{%
  \vskip #1%
  \vb@t@z{\rlap{\move@topl\hskip\useplength{foldmarkhpos}%
    \rule{#2}{.2pt}}}%
  \vskip -#1\ignorespaces%
}
\newcommand*{\@foldmarks}{%
  \if@fold%
    \typeout{Foldmarks: yes}%
    \move@topt
    \@foldmark{\useplength{tfoldmarkvpos}}{2mm}
    \@foldmark{.5\paperheight}{4mm}
    \@foldmark{\useplength{bfoldmarkvpos}}{2mm}
    \move@frompt
  \else
    \typeout{Foldmarks: no}%
  \fi%
}

我也改成了,\newcommand*{\opening}[1]{\def\@opening{#1}}因为\newcommand*{\opening}[1]{\def\@foldmarks\@opening{#1}}也发生了类似的事情scrlttr2.cls

现在,除了仍然引用的几个指令scrlttr2(例如\ClassError{scrlttr2}{%)之外,我在编译时收到以下错误:

This is pdfTeX, Version 3.1415926-2.5-1.40.14 (TeX Live 2013
Processing: ./template.tex
Document Class: moderncv 2013/04/29 v1.5.1 modern curriculum vitae and letter document class
LaTeX Font Warning: Font shape `OMS/qpl/m/n' undefined
Latex Error: ./template.tex:68 Undefined control sequence.
LaTeX Font Warning: Font shape `T1/lmss/sb/n' undefined
LaTeX Warning: Citation `book1' on page 3 undefined on input line 145.
LaTeX Font Warning: Some font shapes were not available, defaults substituted.
LaTeX Warning: There were undefined references.
Output written on template.pdf (3 pages, 216601 bytes).
Complete transcript is in template.log
Found 1 errors, and 5 warnings in 1 runs
/Users/stefano/Library/Application\ Support/TextMate/Managed/Bundles/LaTeX.tmbundle/Support/bin/latexmk.pl -pdf -f -r /tmp/latexmkrc "template.tex" exited with status 12

有问题的命令是\makelettertitle,该命令负责渲染字母开头。我试图找出还要更改什么,但这超出了我的理解范围。有人可以解释一下我遗漏了什么以及如何继续吗?谢谢。

答案1

我们可以尝试劫持 KOMA-Script 提供的折叠标记位置的值,并使用 TikZ 绘制它们。我认为这应该适用于任何文档类。

\documentclass[a4paper]{article}

\usepackage{tikz}

\makeatletter
  \def\loadfoldmarkdims#1{%
    \begingroup
      \let\LetterOptionNeedsPapersize\@gobbletwo
      \def\setkomavar{\@ifstar{\@gobbletwo}{\@gobbletwo}}%
      \def\scr@compatibility##1\relax{0>0\relax}%
      \def\@alignfrom{0}%
      \let\KOMAoptions\@gobble
      \let\newkomavar\@gobble
      \let\l@addto@macro\@gobbletwo
      \let\addtoreffields\@gobble
      \let\setkomafont\@gobbletwo
      \newcommand*{\@newplength}[1]{%
        \@ifundefined{ltr@len@##1}{%
          \expandafter\let\csname notscr@len@##1\endcsname=\z@%
        }{}%
      }%
      \newcommand*{\useplength}[1]{%
        \glueexpr \csname notscr@len@##1\endcsname\relax}%
      \newcommand*{\setlengthtoplength}[3][]{%
        \setlength{##2}{\useplength{##3}}%
        \setlength{##2}{##1##2}}
      \newcommand*{\@setplength}[3][]{%
        \begingroup%
          \setlength{\@tempskipa}{\glueexpr ##3\relax}%
          \setlength{\@tempskipa}{##1\@tempskipa}%
          \edef\@tempa{\endgroup\def\expandafter\noexpand\csname notscr@len@##2\endcsname{\the\@tempskipa}}%
        \@tempa
      }%
      \newcommand*{\addtolengthplength}[3][]{%
        \begingroup%
          \setlengthtoplength[{##1}]{\@tempskipa}{##3}%
          \edef\@tempa{\endgroup\noexpand\addtolength{##2}{\the\@tempskipa}}%
        \@tempa%
      }%
      \newcommand*{\@addtoplength}[3][]{%
        \begingroup%
          \setlength{\@tempskipa}{\glueexpr ##3\relax}%
          \setlength{\@tempskipa}{##1\@tempskipa}%
          \addtolengthplength{\@tempskipa}{##2}%
          \edef\@tempa{\endgroup\def\expandafter\noexpand\csname ltr@len@##2\endcsname{\the\@tempskipa}}%
        \@tempa%
      }%
      \@newplength{foldmarkhpos}%
      \@newplength{foldmarkvpos}%
      \@newplength{tfoldmarkvpos}%
      \@newplength{mfoldmarkvpos}%
      \@newplength{bfoldmarkvpos}%
      \@newplength{lfoldmarkhpos}%
      \@newplength{pfoldmarklength}%
      \@newplength{tfoldmarklength}%
      \@newplength{mfoldmarklength}%
      \@newplength{bfoldmarklength}%
      \@newplength{lfoldmarklength}%
      \@newplength{foldmarkthickness}%
      \@setplength{foldmarkthickness}{.2pt}%
      \input{#1.lco}%
      \def\@makeglobal##1{%
        \global\expandafter\let\csname @##1\expandafter\endcsname\csname notscr@len@##1\endcsname
      }%
      \@makeglobal{foldmarkhpos}%
      \@makeglobal{foldmarkvpos}%
      \@makeglobal{tfoldmarkvpos}%
      \@makeglobal{mfoldmarkvpos}%
      \@makeglobal{bfoldmarkvpos}%
      \@makeglobal{lfoldmarkhpos}%
      \@makeglobal{pfoldmarklength}%
      \@makeglobal{tfoldmarklength}%
      \@makeglobal{mfoldmarklength}%
      \@makeglobal{bfoldmarklength}%
      \@makeglobal{lfoldmarklength}%
      \@makeglobal{foldmarkthickness}%
    \endgroup
  }
  \loadfoldmarkdims{DIN}

  \def\foldmarkdim#1#2{%
    \csname @#1foldmark#2\endcsname
  }
  \def\setfoldmarkdim#1#2#3{%
    \expandafter\def\csname @#1foldmark#2\endcsname{#3}%
  }

  \def\@new@foldmarkif#1{%
    \expandafter\newif\csname if@#1foldmark\endcsname
    \csname @#1foldmarktrue\endcsname
  }
  \@new@foldmarkif{p}
  \@new@foldmarkif{t}
  \@new@foldmarkif{m}
  \@new@foldmarkif{b}
  \@new@foldmarkif{l}
  \def\foldmarkifenabled#1{%
    \csname if@#1foldmark\endcsname
      \expandafter\@firstoftwo
    \else
      \expandafter\@secondoftwo
    \fi
  }
  \def\foldmarkenable#1{%
    \csname @#1foldmarktrue\endcsname
  }
  \def\foldmarkdisable#1{%
    \csname @#1foldmarkfalse\endcsname
  }

  \def\@patch@foldmarkdims{%
    \ifdim \foldmarkdim{p}{length}=\z@
      \setfoldmarkdim{p}{length}{4mm}%
    \fi
    \ifdim \foldmarkdim{t}{length}=\z@
      \setfoldmarkdim{t}{length}{2mm}%
    \fi
    \ifdim \foldmarkdim{m}{length}=\z@
      \setfoldmarkdim{m}{length}{2mm}%
    \fi
    \ifdim \foldmarkdim{b}{length}=\z@
      \setfoldmarkdim{b}{length}{2mm}%
    \fi
    \ifdim \foldmarkdim{l}{length}=\z@
      \setfoldmarkdim{l}{length}{4mm}%
    \fi
    \setfoldmarkdim{p}{vpos}{.5\paperheight}%
  }

  \newcommand\drawfoldmarks{%
    \begingroup
      \@patch@foldmarkdims
      \begin{tikzpicture}[overlay, remember picture, line width=\foldmarkdim{}{thickness}]
        \foreach \mark in {p, t, m, b} {
          \foldmarkifenabled{\mark}{
            \ifdim \foldmarkdim{\mark}{vpos}=\z@\else
              \draw
                (current page.north west) ++(\foldmarkdim{}{hpos},-\foldmarkdim{\mark}{vpos})
                -- +(\foldmarkdim{\mark}{length},0);
            \fi
          }{}
        }
        \foreach \mark in {l} {
          \foldmarkifenabled{\mark}{
            \ifdim \foldmarkdim{\mark}{hpos}=\z@\else
              \draw
                (current page.north west) ++(\foldmarkdim{\mark}{hpos},-\foldmarkdim{}{vpos})
                 -- +(0,-\foldmarkdim{\mark}{length});
             \fi
           }{}
         }
      \end{tikzpicture}
    \endgroup
  }
\makeatother

\begin{document}

\drawfoldmarks

\end{document}

使用说明:

  • 需要安装 KOMA-Script 才能找到.lco具有尺寸的文件(或者您可以编写自己的文件)。
  • 您可以使用 加载尺寸\loadfoldmarkdims{<filename>}。我调用\loadfoldmarkdims{DIN}来提供一些默认值。这个命令有点不靠谱,因为我刚刚禁用了文件中使用的所有.lco我不关心的命令。我成功地用.lcoKOMA-Script 附带的所有文件测试了它,除了visualize.lco(这应该没关系)。
  • 您可以使用 和 启用或禁用折叠标记\foldmarkenable{<mark>}\foldmarkdisable{<mark>}其中<mark>ptmb之一l。默认情况下,全部启用。
  • 您可以使用 手动设置折叠标记尺寸\setfoldmarkdim{<mark>}{<dim>}{<value>},其中<mark>与上文相同或为空,并且是、或的<dim>匹配值。hposvposlengththickness
  • 适用 KOMA-Script 手册第 22.1.1 节(“折叠标记”)中列出的规则。
  • 将其\drawfoldmarks放在任何您想要折叠标记的页面上。

答案2

面向页面背景有折叠痕迹 您可以尝试以下方法,在 latex 中独立于 documentclass letter 来获取折叠标记

\AddToShipoutPictureBG{
\color{black}
\AtPageLowerLeft{\hdashrule[0.5\paperheight+40mm]{0.4cm}{0.4pt}{6pt 3pt}}
\AtPageLowerLeft{\hdashrule[0.5\paperheight]{0.7cm}{0.4pt}{16pt 3pt}}
\AtPageLowerLeft{\hdashrule[0.5\paperheight-40mm]{0.4cm}{0.4pt}{6pt 3pt}}}

请注意,最后的参数(16pt 和 3pt)是指 dashrule 包中的行长和换行长度选项。

相关内容