Discussion:
\hrule and color
(too old to reply)
Geoff Ostrin
2005-02-04 14:08:47 UTC
Permalink
Dear All,

Hows does one colour an \hrule command?

Many thanks,

Geoff.
Martin Salois
2005-02-04 14:14:44 UTC
Permalink
Post by Geoff Ostrin
Dear All,
Hows does one colour an \hrule command?
Many thanks,
Geoff.
\usepackage{color}
\textcolor{red}{\hrule}

Seems to work perfectly­... ;)

Martin
Donald Arseneau
2005-02-04 21:21:21 UTC
Permalink
Post by Martin Salois
\usepackage{color}
\textcolor{red}{\hrule}
Seems to work perfectly­... ;)
Perfect except for the empty paragraph inserted above it.

\textcolor is for text in a paragraph. Use \color in a
group for other things.
--
Donald Arseneau ***@triumf.ca
Stefan Lagotzki
2005-02-04 15:23:40 UTC
Permalink
Post by Geoff Ostrin
Hows does one colour an \hrule command?
\documentclass{article}
\usepackage{color}
\newcommand{\colorrule}[1]{%
\begingroup\color{#1}\hrule\endgroup%
}%
\begin{document}
\section{Test}
\colorrule{red}
\end{document}

%% HTH, Stefan
Geoff Ostrin
2005-02-06 13:02:02 UTC
Permalink
Post by Martin Salois
Post by Geoff Ostrin
Hows does one colour an \hrule command?
\usepackage{color}
\begingroup\color{#1}\hrule\endgroup%
Thankyou for the replies. I see that this works, but within the
package I am using it does not seem to nest. I am using proof.sty,
this enables me to make proof trees of the form
A B
-----
C

When I dig into this package I find the following:

\setbox\ResultBox=\vbox{
\moveright \UpperAdjust \box\@UpperPart
\nointerlineskip \kern\inferLineSkip
\moveright \RuleAdjust \vbox{\hrule width\RuleWidth}\relax
\nointerlineskip \kern\inferLineSkip
\moveright \LowerAdjust \box\@LowerPart }\relax


This is the only place where \hrule appears and I know that it draws
the appropriate line. I can colour this line, but when I nest the
command being defined so that I can have a tree as follows:

A
---
B C
------
D

I cannot obtain the rules in different colours, it seems to always
default to black. Any ideas?

Many thanks in advance,

Geoff.

ps: here is the style package proof.sty....


% proof.sty (Proof Figure Macros)
%
% version 1.0
% October 13, 1990
% Copyright (C) 1990 Makoto Tatsuta (***@riec.tohoku.ac.jp)
%
% This program is free software; you can redistribute it or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either versions 1, or (at your option)
% any later version.
%
% This program is distributed in the hope that it will be useful
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% Usage:
% In \documentstyle, specify an optional style `proof', say,
% \documentstyle[proof]{article}.
%
% The following macros are available:
%
% In all the following macros, all the arguments such as
% <Lowers> and <Uppers> are processed in math mode.
%
% \infer<Lower><Uppers>
% draws an inference.
%
% Use & in <Uppers> to delimit upper formulae.
% <Uppers> consists more than 0 formulae.
%
% \infer returns \hbox{ ... } or \vbox{ ... } and
% sets \@LeftOffset and \@RightOffset globally.
%
% \infer[<Label>]<Lower><Uppers>
% draws an inference labeled with <Label>.
%
% \infer*<Lower><Uppers>
% draws a many step deduction.
%
% \infer*[<Label>]<Lower><Uppers>
% draws a many step deduction labeled with <Label>.
%
% \deduce<Lower><Uppers>
% draws an inference without a rule.
%
% \deduce[<Proof>]<Lower><Uppers>
% draws a many step deduction with a proof name.
%
% Example:
% If you want to write
% B C
% -----
% A D
% ----------
% E
% use
% \infer{E}{
% A
% &
% \infer{D}{B & C}
% }
%

% Style Parameters

% added by GEO. 3.2.05
\newcommand{\proofrulecolor}{black}
\newcommand{\hruleg}{\begingroup\color{\proofrulecolor}\hrule
width\RuleWidth\relax\endgroup}% correct
%\newcommand{\hruleg}{\hrule}
%\begingroup\color{#1}\hrule\endgroup


\newdimen\inferLineSkip \inferLineSkip=2pt
\newdimen\inferLabelSkip \inferLabelSkip=5pt
\def\inferTabSkip{\quad}

% Variables

\newdimen\@LeftOffset % global
\newdimen\@RightOffset % global
\newdimen\@SavedLeftOffset % safe from users

\newdimen\UpperWidth
\newdimen\LowerWidth
\newdimen\LowerHeight
\newdimen\UpperLeftOffset
\newdimen\UpperRightOffset
\newdimen\UpperCenter
\newdimen\LowerCenter
\newdimen\UpperAdjust
\newdimen\RuleAdjust
\newdimen\LowerAdjust
\newdimen\RuleWidth
\newdimen\HLabelAdjust
\newdimen\VLabelAdjust
\newdimen\WidthAdjust

\newbox\@UpperPart
\newbox\@LowerPart
\newbox\@LabelPart
\newbox\ResultBox

% Flags

\newif\***@inferRule % whether \@infer draws a rule.
\newif\***@ReturnLeftOffset % whether \@infer returns \@LeftOffset.
\newif\***@MathSaved % whether inner math mode where \infer or
% \deduce appears.

% Special Fonts

\def\DeduceSym{\vtop{\baselineskip4\p@ \lineskiplimit\z@
\vbox{\hbox{.}\hbox{.}\hbox{.}}\hbox{.}}}

% Math Save Macros
%
% \@SaveMath is called in the very begining of toplevel macros
% which are \infer and \deduce.
% \@RestoreMath is called in the very last before toplevel macros end.
% Remark \infer and \deduce ends calling \@infer.

\def\@SaveMath{\@MathSavedfalse \ifmmode \ifinner
\relax $\relax \@MathSavedtrue \fi\fi }

\def\@RestoreMath{\***@MathSaved \relax $\relax\fi }

% Macros

\def\@ifEmpty#1#2#3{\def\@tempa{\@empty}\def\@tempb{#1}\relax
\ifx \@tempa \@tempb #2\else #3\fi }

\def\infer{\@SaveMath \@ifnextchar *{\@inferSteps}{\@inferOneStep}}

\def\@inferOneStep{\@inferRuletrue
\@ifnextchar [{\@infer}{\@infer[\@empty]}}

\def\@inferSteps*{\@ifnextchar
[{\@@inferSteps}{\@@inferSteps[\@empty]}}

\def\@@inferSteps[#1]{\@deduce{#1}[\DeduceSym]}

\def\deduce{\@SaveMath \@ifnextchar [{\@deduce{\@empty}}
{\@inferRulefalse \@infer[\@empty]}}

% \@deduce<Proof Label>[<Proof>]<Lower><Uppers>

\def\@deduce#1[#2]#3#4{\@inferRulefalse
\@infer[\@empty]{#3}{\@SaveMath \@infer[{#1}]{#2}{#4}}}

% \@infer[<Label>]<Lower><Uppers>
% If \@inferRuletrue, draws a rule and <Label> is right to
% a rule.
% Otherwise, draws no rule and <Label> is right to <Lower>.

\def\@infer[#1]#2#3{\relax
% Get parameters
\***@ReturnLeftOffset \else \@SavedLeftOffset=\@LeftOffset \fi
\setbox\@LabelPart=\hbox{$#1$}\relax
\setbox\@LowerPart=\hbox{$#2$}\relax
%
\global\@LeftOffset=0pt
\setbox\@UpperPart=\vbox{\tabskip=0pt \halign{\relax
\global\@RightOffset=0pt \@ReturnLeftOffsettrue $##$&&
\inferTabSkip
\global\@RightOffset=0pt \@ReturnLeftOffsetfalse $##$\cr
#3\cr}}\relax
% Here is a little trick.
% \@ReturnLeftOffsettrue(false) influences on \infer or
% \deduce placed in ## locally
% because of \@SaveMath and \@RestoreMath.
\UpperLeftOffset=\@LeftOffset
\UpperRightOffset=\@RightOffset
% Calculate Adjustments
\LowerWidth=\wd\@LowerPart
\LowerHeight=\ht\@LowerPart
\LowerCenter=0.5\LowerWidth
%
\UpperWidth=\wd\@UpperPart \advance\UpperWidth by -\UpperLeftOffset
\advance\UpperWidth by -\UpperRightOffset
\UpperCenter=\UpperLeftOffset
\advance\UpperCenter by 0.5\UpperWidth
%
\ifdim \UpperWidth > \LowerWidth
% \UpperCenter > \LowerCenter
\UpperAdjust=0pt
\RuleAdjust=\UpperLeftOffset
\LowerAdjust=\UpperCenter \advance\LowerAdjust by -\LowerCenter
\RuleWidth=\UpperWidth
\global\@LeftOffset=\LowerAdjust
%
\else % \UpperWidth <= \LowerWidth
\ifdim \UpperCenter > \LowerCenter
%
\UpperAdjust=0pt
\RuleAdjust=\UpperCenter \advance\RuleAdjust by -\LowerCenter
\LowerAdjust=\RuleAdjust
\RuleWidth=\LowerWidth
\global\@LeftOffset=\LowerAdjust
%
\else % \UpperWidth <= \LowerWidth
% \UpperCenter <= \LowerCenter
%
\UpperAdjust=\LowerCenter \advance\UpperAdjust by -\UpperCenter
\RuleAdjust=0pt
\LowerAdjust=0pt
\RuleWidth=\LowerWidth
\global\@LeftOffset=0pt
%
\fi\fi
% Make a box
\***@inferRule
%
\setbox\ResultBox=\vbox{
\moveright \UpperAdjust \box\@UpperPart
\nointerlineskip \kern\inferLineSkip
\moveright \RuleAdjust \vbox{\hrule width\RuleWidth}\relax
\nointerlineskip \kern\inferLineSkip
\moveright \LowerAdjust \box\@LowerPart }\relax
%
\@ifEmpty{#1}{}{\relax
%
\HLabelAdjust=\wd\ResultBox \advance\HLabelAdjust by -\RuleAdjust
\advance\HLabelAdjust by -\RuleWidth
\WidthAdjust=\HLabelAdjust
\advance\WidthAdjust by -\inferLabelSkip
\advance\WidthAdjust by -\wd\@LabelPart
\ifdim \WidthAdjust < 0pt \WidthAdjust=0pt \fi
%
\VLabelAdjust=\dp\@LabelPart
\advance\VLabelAdjust by -\ht\@LabelPart
\VLabelAdjust=0.5\VLabelAdjust \advance\VLabelAdjust by \LowerHeight
\advance\VLabelAdjust by \inferLineSkip
%
\setbox\ResultBox=\hbox{\box\ResultBox
\kern -\HLabelAdjust \kern\inferLabelSkip
\raise\VLabelAdjust \box\@LabelPart \kern\WidthAdjust}\relax
%
}\relax % end @ifEmpty
%
\else % \@inferRulefalse
%
\setbox\ResultBox=\vbox{
\moveright \UpperAdjust \box\@UpperPart
\nointerlineskip \kern\inferLineSkip
\moveright \LowerAdjust \hbox{\unhbox\@LowerPart
\@ifEmpty{#1}{}{\relax
\kern\inferLabelSkip \unhbox\@LabelPart}}}\relax
\fi
%
\global\@RightOffset=\wd\ResultBox
\global\advance\@RightOffset by -\@LeftOffset
\global\advance\@RightOffset by -\LowerWidth
\***@ReturnLeftOffset \else \global\@LeftOffset=\@SavedLeftOffset \fi
%
\box\ResultBox
\@RestoreMath
}
Donald Arseneau
2005-02-08 04:43:56 UTC
Permalink
When I dig into this package I find...
\setbox\ResultBox=\vbox{...
This is the only place where \hrule appears and I know that it draws
the appropriate line. I can colour this line, but when I nest the
command being defined ...
I cannot obtain the rules in different colours, it seems to always
default to black. Any ideas?
Of course not! You don't show anything that colors the rules
at all.

I see a definition of \hruleg, but no use.

I see a definition of \proofrulecolor as black, but no attemt
to change that color.
--
Donald Arseneau ***@triumf.ca
Geoff Ostrin
2005-02-09 11:15:47 UTC
Permalink
Post by Donald Arseneau
When I dig into this package I find...
\setbox\ResultBox=\vbox{...
This is the only place where \hrule appears and I know that it draws
the appropriate line. I can colour this line, but when I nest the
command being defined ...
I cannot obtain the rules in different colours, it seems to always
default to black. Any ideas?
Of course not! You don't show anything that colors the rules
at all.
I see a definition of \hruleg, but no use.
I see a definition of \proofrulecolor as black, but no attemt
to change that color.
Yes you are correct. In fact, I added the two definitions above so
that I could manipulate the file easily, I just forgot to edit them
out of the package when I copied and pasted. Thus, in the original
package there is no mention of colours whatsoever. My idea was to
define a macro that had 4 inputs: say \proofrule{premise}{rule
name}{rule colour}{conclusion}

Now alone this worked. i.e. if I typed \proofrule{A}{R}{blue}{C} then
I would get

A
-- R
C

with the rule coloured blue. But when I did,

\proofrule{\proofrule{A}{R}{blue}{C}}{R'}{red}{D}

I obtained

A
-- R
C
-- R'
D

but all the rules were black! Hence my question. I hope this helps,
any ideas?

Geoff.
Donald Arseneau
2005-02-09 21:21:41 UTC
Permalink
Post by Geoff Ostrin
Post by Donald Arseneau
Of course not! You don't show anything that colors the rules
at all.
define a macro that had 4 inputs: say \proofrule{premise}{rule
name}{rule colour}{conclusion}
but all the rules were black! Hence my question. I hope this helps,
Not really.

Nobody can say how it doesn't work unless they can see
the definition.
--
Donald Arseneau ***@triumf.ca
Geoff Ostrin
2005-02-10 09:43:31 UTC
Permalink
Post by Donald Arseneau
Nobody can say how it doesn't work unless they can see
the definition.
Good point! OK, I'll post a minimal example. I obtained the proof.sty
package from http://research.nii.ac.jp/~tatsuta/proof.sty but I have
modified it in two parts:

1: I added in at the beginning \newcommand{\proofrulecolor}{black}

2: I modified lines 233/4 so that it includes a colour so that the
original
lines 233/4: \moveright \RuleAdjust \vbox{\hrule width\RuleWidth
\kern 1pt\hrule width\RuleWidth}\relax

become my version lines 233/4: \moveright\RuleAdjust
\vbox{\begingroup\color{\proofrulecolor}\hrule width\RuleWidth
\kern 1pt\hrule
width\RuleWidth\endgroup}\relax

Now I define \proofrule, it is just \infer with the inputs in an order
I can more easily follow, plus a colour name for the rule.


\documentclass{article}
\usepackage{color,proof}

\newcommand{\proofrule}[4]{\renewcommand{\proofrulecolor}{#3}\infer[#2]{#4}{#1}}


\begin{document}

This works with blue: \proofrule{premise1}{rule1}{blue}{conclusion1}

This works with red: \proofrule{premise2}{rule2}{red}{conclusion2}

But when I nest them it doesn't work:
\proofrule{
\proofrule{premise1}{rule1}{blue}{conclusion1}
&
\proofrule{premise2}{rule2}{red}{conclusion2}
}{rule3}{green}{conclusion3}

\end{document}
Donald Arseneau
2005-02-14 00:09:11 UTC
Permalink
Post by Geoff Ostrin
become my version lines 233/4: \moveright\RuleAdjust
\vbox{\begingroup\color{\proofrulecolor}\hrule width\RuleWidth
\kern 1pt\hrule
You don't need the grouping, because a \vbox is a local group
anyway.

Also, you must have changed other lines to see any color at all.
What you quote is only for double rules.
Post by Geoff Ostrin
\newcommand{\proofrule}[4]{\renewcommand{\proofrulecolor}{#3}%
\infer[#2]{#4}{#1}}
Here you have redefined \proofrulecolor permanently, not in
a local group. I will assume you tried grouping, but got errors.
Unfortunately proof.sty has some goofy \@SaveMath macro that
prevents your using grouping, and which I think is a really bad
mistake. Complain to the author and get him to eliminate that bug
(by eliminating the save-restore math completely).

In the meantime, work around the error by avoiding math -- use
\mbox{ } for the local grouping:

\newcommand{\proofrule}[4]{\mbox{%
\renewcommand{\proofrulecolor}{#3}\infer[#2]{#4}{#1}}}


Donald Arseneau ***@triumf.ca
Geoff Ostrin
2005-02-14 12:50:32 UTC
Permalink
Post by Donald Arseneau
\newcommand{\proofrule}[4]{\mbox{%
\renewcommand{\proofrulecolor}{#3}\infer[#2]{#4}{#1}}}
You are right; I needed to change all the \hrule's to
\color{\proofrulecolor}\hrule. Then add in the \mbox as you said and
it works. Many thanks for your help, very much appreciated.

Geoff.

Loading...