# [pstricks] pspicture: shift vs. baseline

Bernd Westphal Bernd.Westphal at Informatik.Uni-Oldenburg.DE
Mon Jul 31 14:16:49 CEST 2006

Moin.

First of all, thanks for your advice, Herbert and Antonio.

In the meantime I actually treated it for myself but refrained from posting it
to the list.  For the archive, I've attached it here.  Maybe it'll be of
use to someone.

As I actually need to provide LaTeX sources which compile with both the old and
the new versions of pstricks, I decided to make explicit whether I expect the
"baseline" or the "shift" behaviour and introduced two new LaTeX Environments.

Admittedly it's far less elegant than Antonio's solution as it has a rather
different interface than the original pspicture environment and doesn't
provide new things.  Its only point is that it doesn't redefine commands, but
relies on the "common subset" of the old and the new behaviour.

Schoen'n Gruss
Bernd

- - - 8< - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% $Id: pst-compat.sty,v 1.1 2006/07/10 19:05:01 berndw Exp$
%
% pst-compat -- compatibility fix to provide commands that work with both old
%               and new versions of PSTricks
%
% Author: Bernd Westphal <westphal at informatik.uni-oldenburg.de>
%
%
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
%
% Actually it only
%
%  - provides \psscaleboxto for old versions of PSTricks
%
%  - provides the environments pspicturebaseline/5 and pspictureshift/5
%    as (more or less) drop-in replacement for the pspicture environment.
%
%    The first behaves principally like pspicture in old versions of PSTricks
%    and the second one like new versions.
%
%    That is, if you have code like
%
%      \begin{pspicture}[0.5](x1,y1)(x2,y2)
%
%    which positions the baseline at 0.5 of the height, then you replace it by
%
%      \begin{pspicturebaseline}{0.5}{x1}{y1}{x2}{y2}
%
%    and if you have code like
%
%      \begin{pspicture}[shift=0.5](x1,y1)(x2,y2)
%
%    which positions the baseline 0.5 units from the bottom, then you replace
%    it by
%
%      \begin{pspictureshift}{0.5}{x1}{y1}{x2}{y2}
%
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
%
% This work may be distributed and/or modified under the conditions of
% the LaTeX Project Public License, either version 1.3 of this license
% or (at your option) any later version.
%   http://www.latex-project.org/lppl.txt
% and version 1.3 or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
%
% This work has the LPPL maintenance status maintained'.
%
% The Current Maintainer of this work is the copyright holder.
%
% This work consists of the file pst-compat.sty.
%
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{pst-compat}[2006/07/11 PSTricks compatibility crufts]

\RequirePackage{ifthen,pstricks}

% newer versions of pstricks define \psscaleboxto instead of \scaleboxto; when
% using an older version, define \psscaleboxto for compatibility
%
\providecommand{\psscaleboxto}{\scaleboxto}
%
% workaround for different versions of pstricks -- newer ones use 'shift='
% where the older ones accept the number directly.
% 2004/05/12 is an old version for teTeX 3.0 on the composers.  We're looking
% for 2004/05/13 because the macro seems to be "if-package-strictly-later".
%
% \pspicturebaseline{<baseline>}{<x1>}{<y1>}{<x2>}{<y2>}%
% \pspictureshift{<shift>}{<x1>}{<y1>}{<x2>}{<y2>}%
%
\newsavebox{\pstcompat at box}%
\newlength{\pstcompatshift at L}%
%
\@ifpackagelater{pstricks}{2004/05/13}%
{%
\newlength{\pstcompatshift at A}%
\newlength{\pstcompatshift at B}%
%
\newenvironment{pspicturebaseline}[5]{%
\pssetlength{\pstcompatshift at A}{#3}%
\pssetlength{\pstcompatshift at B}{#5}%
\ifthenelse{\lengthtest{\pstcompatshift at A<\pstcompatshift at B}}{%
\relax%
}{%
\pssetlength{\pstcompatshift at A}{#5}%
\pssetlength{\pstcompatshift at B}{#3}%
}%
\pssetlength{\pstcompatshift at L}{\pstcompatshift at A}%
\ifthenelse{\equal{#1}{}}{%
\relax%
}{%
\psaddtolength{\pstcompatshift at L}{-\pstcompatshift at B}%
\pssetlength{\pstcompatshift at L}{#1\pstcompatshift at L}%
}%
\begin{lrbox}{\pstcompat at box}%
\begin{pspicture}(#2,#3)(#4,#5)%
}{%
\end{pspicture}%
\end{lrbox}%
\raisebox{\pstcompatshift at L}{\usebox{\pstcompat at box}}%
}%
}{%
\newenvironment{pspicturebaseline}[5]{%
\begin{pspicture}[#1](#2,#3)(#4,#5)%
}{%
\end{pspicture}%
}%
}

\newenvironment{pspictureshift}[5]{%
\pssetlength{\pstcompatshift at L}{#1}%
\begin{lrbox}{\pstcompat at box}%
\begin{pspicture}(#2,#3)(#4,#5)%
}{%
\end{pspicture}%
\end{lrbox}%
\raisebox{\pstcompatshift at L}{\usebox{\pstcompat at box}}%
}

\endinput
- - - 8< - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Antonio Polo wrote:
> On 2006, July 4th, Bernd Westphal wrote:
> > Moin.
> > If I understand it correctly, old versions of pstricks use
> >   \begin{pspicture}[0.5]
> > to set the baseline at half the height of the box and
> >   \begin{pspicture}[]
> > puts the baseline through the origin.
> > The newer versions only have 'shift' where
> >   \begin{pspicture}[shift=0.5]
> > shifts by 0.5 "units", i.e. not related to the box' height.
> > Is there a way to obtain the "old" behaviour with the newer versions, other
> > than explicitly calculating the height and setting shift correspondingly?
> > Is there in particular an easy way to put the baseline through the origin
> > with the newer versions?
> > Schoen'n Gruss
> >   Bernd Westphal
>
> I had the same problem, expecially when I tried to use old pspictures with the
> new version of pstricks: the problem is not to calculate the shift parameter
> for the new pictures, but to re-edit and re-calculate it for the old ones. I
> solved this problem by myself and also I (think to have) solved the problems
> of compatibility of the old version with the new one; after the loading of
> pstricks package, you put these lines in your preamble:
>
> %---------------------------------------------------------------------------
> %--begin-------Re-definition of "\pst at picture"-------------------------
> %---------------------------------------------------------------------------
[...]
> %---------------------------------------------------------------------------
> %---end--------Re-definition of "\pst at picture"-------------------------
> %---------------------------------------------------------------------------
>
> Obviously it would be better to change the command directly in the
> "pstricks.tex" file, but I can't do it and these lines work fine too.
> With this change, the environment "pspicture" works so:
>
> 1)\begin{pspicture}[<number>]...
> It shifts the baseline linearly along the height of the pspicture.
> <number>=0 means "bottom" and <number>=1 means "top";
> all decimal numbers are allowed.
>
> 2)\begin{pspicture}[]...
> The baseline is aligned with the origin of the pspicture.
>
> 3)\begin{pspicture}[<letter>]...
> This is something more:
> <letter>=b same as <number>=0: baseline aligned with the bottom
> <letter>=c same as <number>=0.5: baseline aligned with the center
> <letter>=t same as <number>=1: baseline aligned with the top
> <letter>=o means baseline aligned with the origin
> Expecially the last is useful with the next case.
>
> 4)\begin{pspicture}[...,<option>,<number> or <letter>,<option>...]...
> You can put the number or the letter also between the other classical options
> such as "showgrid=true", "linestyle=dashed" and so on.
>
> Now I hope you enjoy shifting pspictures.
>
> Toni
>

`