From e6d386262744c2cfe0c5b72c9682dc7e121e8a15 Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Sun, 25 Nov 2012 06:22:21 -0700 Subject: [PATCH] scribble latex: work around `\href{...#...}{...}' as a macro argument The `math' document build was failing because `\marginpar' does not like `\href{...#...}{...}' as an argument. original commit: 24f358a5d7afca40fcf734af94c2c94a80a817dc --- collects/scribble/latex-render.rkt | 19 +++++++++++++------ collects/scribble/scribble.tex | 4 ++++ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/collects/scribble/latex-render.rkt b/collects/scribble/latex-render.rkt index 082a7e54..7873025d 100644 --- a/collects/scribble/latex-render.rkt +++ b/collects/scribble/latex-render.rkt @@ -391,12 +391,19 @@ (let ([v (car l)]) (cond [(target-url? v) - (printf "\\href{~a}{" (regexp-replace* #rx"%" - (let ([p (target-url-addr v)]) - (if (path? p) - (path->string p) - p)) - "\\\\%")) + (define target (regexp-replace* #rx"%" + (let ([p (target-url-addr v)]) + (if (path? p) + (path->string p) + p)) + "\\\\%")) + (if (regexp-match? #rx"^[^#]*#[^#]*$" target) + ;; work around a problem with `\href' as an + ;; argument to other macros, such as `\marginpar': + (let ([l (string-split target "#")]) + (printf "\\Shref{~a}{~a}{" (car l) (cadr l))) + ;; normal: + (printf "\\href{~a}{" target)) (loop (cdr l) #t) (printf "}")] [(color-property? v) diff --git a/collects/scribble/scribble.tex b/collects/scribble/scribble.tex index b7ec1d86..5d36fc5a 100644 --- a/collects/scribble/scribble.tex +++ b/collects/scribble/scribble.tex @@ -190,6 +190,10 @@ % Helper for box-mode macros: \newcommand{\Svcenter}[1]{$\vcenter{#1}$} +% Helper to work around a problem with "#"s for URLs within \href +% within other macros: +\newcommand{\Shref}[3]{\href{#1\##2}{#3}} + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Scribble then generates the following: