Skip to content

Commit

Permalink
Try making \code and \samp robust and consistent re no ligatures.
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.r-project.org/R/trunk@58096 00db46b3-68df-0310-9c12-caf00c1e9a41
  • Loading branch information
hornik committed Jan 12, 2012
1 parent 9204c28 commit 80430ef
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
34 changes: 24 additions & 10 deletions share/texmf/tex/latex/Rd.sty
Expand Up @@ -206,23 +206,37 @@
\newcommand{\email}[1]{\normalfont\texttt{\textless#1\textgreater}}
%% \code without `-' ligatures
{\catcode`\-=\active%
\global\def\code{\bgroup%
\catcode`\-=\active \let-\codedash%
\Rd@code}}
\def\codedash{-\discretionary{}{}{}}
\def\Rd@code#1{\normalfont\texttt{#1}\egroup}
\def\AsIs{\bgroup\let\do\@makeother\Rd@AsIs@dospecials\@noligs\@vobeyspaces\Rd@AsIsX}
\def\Rd@AsIs@dospecials{\do\$\do\&\do\#\do\^\do\_\do\%\do\~}
\def\Rd@AsIsX#1{\normalfont #1\egroup}
%{\catcode`\-=\active%
% \global\def\code{\bgroup%
% \catcode`\-=\active \let-\codedash%
% \Rd@code}}
% \def\codedash{-\discretionary{}{}{}}
%% If we simply do
%% \DeclareRobustCommand\code{\bgroup\@noligs\@vobeyspaces\Rd@code}
%% then e.g.
%% \code{\LinkA{attr<-}{attr<.Rdash.}}
%% will give an undefined control sequence `\< error when hyperref is
%% used (so that \LinkA uses \hyperlink).
%% Hence, use a noligs list without < and > for now, and use the same
%% list for \code and \samp and their variants.
\def\Rd@nolig@list{\do\`\do\,\do\'\do\-}
\def\Rd@noligs{\let\do\do@noligs \Rd@nolig@list}
\DeclareRobustCommand\code{\bgroup\Rd@noligs\@vobeyspaces\Rd@code}
\def\Rd@code#1{\normalfont\texttt{#1}\egroup}
\let\command=\code
\let\env=\code
\newcommand\samp{`\bgroup\@noligs\@vobeyspaces\@sampx}
\DeclareRobustCommand\samp{`\bgroup\Rd@noligs\@vobeyspaces\@sampx}
\def\@sampx#1{{\normalfont\texttt{#1}}\egroup'}
\let\option=\samp
\def\AsIs{\bgroup\let\do\@makeother\Rd@AsIs@dospecials\@noligs\@vobeyspaces\Rd@AsIsX}
\def\Rd@AsIs@dospecials{\do\$\do\&\do\#\do\^\do\_\do\%\do\~}
\def\Rd@AsIsX#1{\normalfont #1\egroup}
% This is a workaround for the old Rdconv to handle \Sexpr by echoing it
% Rd2latex() should never let \Sexpr through to here.
\newcommand\Sexpr[2][]{{\normalfont\texttt{\bsl Sexpr[#1]\{#2\}}}}
Expand Down
4 changes: 2 additions & 2 deletions src/library/grid/vignettes/grid.Rnw
Expand Up @@ -87,7 +87,7 @@ grid.show.viewport(viewport(x = 0.5, y = 0.5, width = 0.5, height = 0.25,
\caption{
\label{figure:viewport}
A diagram of a simple \grid{} viewport (produced using the
\protect\code{grid.show.viewport()} function.}
\code{grid.show.viewport()} function.}
\end{figure}

The object returned by the \code{viewport()} function is only a
Expand Down Expand Up @@ -524,7 +524,7 @@ popViewport(2)
}
\end{center}
\caption{\label{figure:simpleplot}
The grid equivalent of \protect\code{plot(1:10)}.}
The grid equivalent of \code{plot(1:10)}.}
\end{figure}

Now consider a more complex example, where we create a barplot
Expand Down

0 comments on commit 80430ef

Please sign in to comment.