更改 catcode 和票证(名片打印)和表格

更改 catcode 和票证(名片打印)和表格

更新,很晚了

不要这样做。请改用字体。这只会在意想不到且难以调试的地方造成很多麻烦。请参阅另一个答案针对同一问题了解详情。

改变数字零的斜线方向

这个答案0我学会了如何更改块内数字中斜线的方向texttt。这种方法很好用,但在票务环境中却不行。

注意我们使用 pdflatex(运行两次)。

商业名片

南加州大学

\documentclass[a4paper,11pt]{article}
\usepackage[zw32010,boxed]{ticket}% for debugging
\RequirePackage[utf8]{inputenc}
\RequirePackage[pdftex]{graphics}
\RequirePackage{ngerman}
\RequirePackage[ngerman]{babel}
\RequirePackage[T1]{fontenc}
\RequirePackage{pxfonts}
\renewcommand{\familydefault}{\sfdefault}

\newcommand\0{\scalebox{-1}[1]{0}}
\let\svttfamily\ttfamily
\let\svtexttt\texttt
\catcode`0=\active
\def0{\0}
\renewcommand\ttfamily{\svttfamily\catcode`0=\active }
\renewcommand\texttt{\bgroup\ttfamily\texttthelp}
\def\texttthelp#1{#1\egroup}
\catcode`0=12

\renewcommand{\ticketdefault}{
    \put(1,46){\LARGE SSCCE}
    \put(2,38){texttt:}
    \put(2,32){implicit:}
    \put(2,26){explicit:}
}

\newcommand{\vcard}[1]{\ticket{
    \put(30,38){\texttt{#1}}
    \put(30,32){\ttfamily #1}
    \put(30,26){\ttfamily\catcode`0=\active #1}
}}

\begin{document}

\vcard{x0y}

\vspace{10cm}

Outside, \texttt{a0b} with texttt.

\end{document}

如您所见,斜线穿过 ,0从左下角到右上角,但我似乎无法让它在名片内部工作。我起初以为这是因为,但将或 的\put文本“原始”地放在 中,即不在 内,也不能解决这个问题:\ticketdefault\ticket\put

\newcommand{\vcard}[1]{\ticket{

        Outside \texttt{m0n} with texttt.

        \put(30,38){\texttt{#1}}
        \put(30,32){\ttfamily #1}
        \put(30,26){\ttfamily\catcode`0=\active #1}
}}

(同样适用于\ticketdefault

\RequirePackage[utf8]{inputenc}
\RequirePackage[pdftex]{graphics}
\RequirePackage[T1]{fontenc}
\RequirePackage{textcomp}
\RequirePackage{graphicx}
\RequirePackage{pxfonts}
\renewcommand{\familydefault}{\sfdefault}
\RequirePackage{hyphenat}

\documentclass{scrartcl}

\newcommand\0{\scalebox{-1}[1]{0}}
\let\svttfamily\ttfamily
\let\svtexttt\texttt
\catcode`0=\active
\def0{\0}
\renewcommand\ttfamily{\svttfamily\catcode`0=\active }
\renewcommand\texttt{\bgroup\ttfamily\texttthelp}
\def\texttthelp#1{#1\egroup}
\catcode`0=12

\usepackage{tabu}
\usepackage{longtable}

\usepackage[export]{adjustbox}

\begin{document}

Das kann doch nicht sein! foo0bar \texttt{baz0blah} meh!

 \begin{longtabu} to \linewidth {|@{}c@{}|X|X|l|l|l|l|}
\hline\rowfont\bfseries Foto & Nachname & Vorname & Geburts\-datum & Benutzer & Fahrt & Fahr\-karte \\\hline
\endhead
x & \nohyphens{Lastname} & \nohyphens{Firstname} & \nohyphens{1970-01-01} & \texttt{hal2001} & \nohyphens{nein} & \nohyphens{nein}\\\hline
 \end{longtabu}
\end{document}

正如你所见,这在表格中也不起作用☹

答案1

您必须0在吸收论点之前激活;我还提出了反向斜线零宏的固定版本。

\documentclass[a4paper,11pt]{article}
\usepackage[zw32010,boxed]{ticket}% for debugging
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}

\usepackage{graphicx}
\usepackage{letltxmacro}
\usepackage{pxfonts}

\renewcommand{\familydefault}{\sfdefault}

\LetLtxMacro\svttfamily\ttfamily
\begingroup\ttfamily\endgroup
\DeclareRobustCommand\ttfamily{%
  \catcode`0=\active
  \svttfamily
}
\LetLtxMacro{\svtexttt}{\texttt}
\DeclareRobustCommand{\texttt}{\begingroup\catcode`0=\active\dotexttt}
\newcommand\dotexttt[1]{\svtexttt{#1}\endgroup}

\newcommand\0{\scalebox{-1}[1]{0}}

\begingroup\lccode`~=`0 \lowercase{\endgroup\def~}{\0}

\renewcommand{\ticketdefault}{%
  \put(1,46){\LARGE SSCCE}%
  \put(2,38){texttt:}%
  \put(2,32){implicit:}%
  \put(2,26){explicit:}%
}

\newcommand{\vcard}{\begingroup\catcode`0=\active\dovcard}
\newcommand{\dovcard}[1]{%
  \ticket{%
    \put(30,38){\texttt{#1}}%
    \put(30,32){\ttfamily#1}%
    \put(30,26){\ttfamily#1}%
  }%
  \endgroup
}

\begin{document}

Outside, \texttt{a0b} with texttt. 

\vcard{x0y}

\end{document}

在此处输入图片描述

一种不同的实现方式expl3,不需要辅助命令\vcard,可以避免分组。

\documentclass[a4paper,11pt]{article}
\usepackage[zw32010,boxed]{ticket}% for debugging
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}

\usepackage{graphicx}
\usepackage{letltxmacro,xparse}
\usepackage{pxfonts}

\renewcommand{\familydefault}{\sfdefault}

\newcommand\0{\scalebox{-1}[1]{0}}

% save the meaning of \ttfamily
\LetLtxMacro\svttfamily\ttfamily
% load the .fd file before changing the meaning of \ttfamily
\begingroup\ttfamily\endgroup

\ExplSyntaxOn
\RenewDocumentCommand{\ttfamily}{}
 {
  \char_set_catcode_active:N 0
  \svttfamily
 }
\RenewDocumentCommand{\texttt}{m}
 {
  \group_begin:
  \ttfamily
  \tl_rescan:nn { } { #1 }
  \group_end:
 }
\ExplSyntaxOff

\begingroup\lccode`~=`0 \lowercase{\endgroup\def~}{\0}

\renewcommand{\ticketdefault}{%
  \put(1,46){\LARGE SSCCE}%
  \put(2,38){texttt:}%
  \put(2,32){implicit:}%
  \put(2,26){explicit:}%
}

\newcommand{\vcard}[1]{%
  \ticket{%
    \put(30,38){\texttt{#1}}%
    \put(30,32){\ttfamily#1}%
    \put(30,26){\ttfamily#1}%
  }%
}

\begin{document}

Outside, \texttt{a0b} with texttt.

Outside, {\ttfamily a0b} with ttfamily.

\vcard{x0y}

\end{document}

在此处输入图片描述

相关内容