How to hijack a key assignment to raise an event that triggers its event handler?
-
Whenever I invoke \degrees the definition of operator au (angle unit) will be updated. It is easily done by redefining the \degrees with \let and \renewcommand. So far so good. Now I want to create two more operators pt2xu and pt2yu which convert pt (point) to the active unit in both x and y direction. Unfortunately, the active unit \psxunit and \psyunit must be updated via key-value assignment so I cannot apply my method with \let and \renewcommand here. Instead I have to create a new macro called \updateoperator. This \updateoperator must be invoked at least once for initialization. The subsequent invocation must be done after we make assignment to unit, xunit and yunit. It is a bad idea to have such an interface as the users might forgot to invoke \updateoperator after doing assignment. My idea is to hijack unit, xunit and yunit assigment such that they silently invoke \updateoperator at least one for initialization and when they are updated via key-value assignment. Do you have any idea to implement it? \documentclass[pstricks,border=12pt]{standalone} \SpecialCoor \makeatletter \let\tempdegrees\degrees \renewcommand\degrees[1][360]{\pstVerb{/au {\pst@angleunit} bind def}\tempdegrees[#1]} \def\updateoperator{\pstVerb{/pt2xu {\pst@number\psxunit div} bind def /pt2yu {\pst@number\psyunit div} bind def}} \makeatother \updateoperator% the first invocation for initialization \begin{document} \begin{pspicture}[showgrid](-1,0)(4,2) \psline[linecolor=red,linewidth=20pt](2,0)(2,1) \psframe*[linecolor=blue](!2 10 pt2yu sub 1)(!2 10 pt2yu add 2) \qdisk(!1 90 PtoC){1} \end{pspicture} \psset{unit=2cm,runit=2cm} \updateoperator \degrees[400] \begin{pspicture}[showgrid](-.5,0)(2,1) \psline[linecolor=red,linewidth=20pt](1,0)(1,.5) \psframe*[linecolor=blue](!1 10 pt2yu sub .5)(!1 10 pt2yu add 1) \qdisk(!.5 100 au PtoC){.5} \end{pspicture} \end{document}
-
Answer:
The argument to the keyword unit is handled by the macro \psset@pstricks@unit. Thus you can hijack the processing of the argument by writing (in a context where @ is a letter, e.g. within a package file): \let\saved@pstricks@unit=\psset@pstricks@unit \def\psset@pstricks@unit#1{% \saved@pstricks@unit{#1}% \updateoperator } The behaviour of the unit keyword is defined in pstricks.tex by the following snippet: \define@key[psset]{pstricks}{unit}[1cm]{% \pssetlength\psunit{#1}% \psxunit=\psunit% \psyunit=\psunit% } If this changes, the synthetised name for the macro \psset@pstricks@unit may also change. A second option could be to hijack the \psset macro as in \let\saved@psset=\psset \def\psset#1{\saved@psset{#1}\updateoperator}
I am who I say I am at TeX - LaTeX Visit the source
Related Q & A:
- How to add primary key from multiple table as a foreign key in a table in sql server 2008?Best solution by stackoverflow.com
- How to pass a parameter to a function that is called on an event?Best solution by Stack Overflow
- How to program a key fob on a 2000 cavalier?Best solution by remotesremotes.com
- How to put a key back onto an Apple laptop?Best solution by Answerbag.com
- How do you change a ford ranger key cylinder without a key?
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.