Aditya101

shading.sty

Jun 23rd, 2020
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Latex 9.09 KB | None | 0 0
  1. %%% ====================================================================
  2. %%%  @LaTeX-style-file{
  3. %%%     filename        = "shading.sty",
  4. %%%     version         = "1.3",
  5. %%%     date            = "29 September 1992",
  6. %%%     time            = "08:23:05 MDT",
  7. %%%     author          = "Art Mulder",
  8. %%%     address         = "Department of Computing Science
  9. %%%                        615 General Services Building
  10. %%%                        University of Alberta
  11. %%%                        Edmonton, Alberta
  12. %%%                        T6G 2H1, Canada.",
  13. %%%     telephone       = "n/a",
  14. %%%     FAX             = "(403) 492-1071",
  15. %%%     checksum        = "06606 232 1004 9082",
  16. %%%     email           = "[email protected]",
  17. %%%     codetable       = "ISO/ASCII",
  18. %%%     keywords        = "LaTeX style option, shaded background",
  19. %%%     supported       = "yes",
  20. %%%     docstring       = "A LaTeX Style file for putting text on a
  21. %%%                        shaded background.  Requires a PostScript
  22. %%%                        printer and dvi-file converter.
  23. %%%
  24. %%%                        NOTE: Art Mulder is not the author
  25. %%%                        of this file, just the most recent
  26. %%%                        modifier.
  27. %%%
  28. %%%                        The style file is based upon ideas by
  29. %%%                        Je'ro^me Maillot, [email protected]
  30. %%%                        which where turned into TeX code by
  31. %%%                        Leo, [email protected].
  32. %%%                        That TeX code was converted into a LaTeX
  33. %%%                        style file by M.A.R. ( [email protected] )",
  34. %%%  }
  35. %%% ====================================================================
  36.  
  37. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  38. % 'Shading.sty'
  39. %
  40. % Art Mulder ( [email protected] ) 28-Sept-1992
  41. %  - Changed name of "linewidth" variable to "outlineboxwidth".
  42. %    That variable name conflicted with another variable of the same
  43. %    name in "latex.tex" when doing miniparagraphs.
  44. %  - Wrote accompanying document ``shading.tex'', brief instructions
  45. %    in the use of this style file, together with several examples.
  46. %
  47. % M.A.R. ( [email protected] ) 22 Jan 92
  48. %  - Modified to work as a LaTeX style:
  49. %  - added setting the grayscale as an optional argument.
  50. %  - allowed multiple paragraphs in the \parashade command
  51. %
  52. % Leo ??  ( [email protected] )
  53. %  - Wrote the original TeX code, based upon some ideas
  54. %    from Je'ro^me Maillot ( [email protected] ).
  55. %
  56. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  57. %
  58. %  USAGE: \textshade[grayscale]{corneroption}{text to be shaded}
  59. %         \parashade[grayscale]{corneroption}{paragraph(s) to be shaded}
  60. %         where
  61. %         grayscale is a number from 0 to 1, the higher the number the
  62. %                   lighter the shading, if missing it is set to 0.95
  63. %         corneroption is either sharpcorners or roundcorners
  64. %
  65. %  LIMITATIONS: --can not break the shaded text across lines (\textshade) or
  66. %                 across pages (both)
  67. %               --can not specify the line width of the surrounding box or
  68. %                 the amount of space between the surrounding
  69. %                 box and the text to be shaded as arguments
  70. %                 (Actually you can, see the use of "\gdef" in the example)
  71. %               --modifying the xgrayspace and ygrayspace in the argument
  72. %                 will only affect the space added to the right and
  73. %                 bottom of the box, respectively
  74. %
  75. %  EXAMPLES:
  76. %    This is a test of a\ \textshade[1]{roundcorners}{shaded box} routine.
  77. %    With a grayscale of 1, we essentially get no shading, and just a box.
  78. %
  79. %    This is another test of a\ \textshade{sharpcorners}{shaded box} routine.
  80. %    The default shading of .95 is used here.
  81. %
  82. %    \parashade[.995]{roundcorners}{\gdef\outlineboxwidth{.5}%
  83. %    This is one very long line which I expect will be broken over one or more
  84. %    lines. The idea is to have this paragraph enclosed in a shaded box. I'll
  85. %    just keep on typing until I can be sure that there are more than two lines
  86. %    in this paragraph. I expect that this should be well and truely sufficient
  87. %    to test this macro.
  88. %    } %This shows an example of changing the outlineboxwidth used, without
  89. %      %changing the style
  90. %
  91. %    The field equations of General Relativity are\ %
  92. %%
  93. %    \textshade{roundcorners}{\hbox{$G_{\mu\nu} = kT_{\mu\nu}$}}
  94. %
  95. %    They can also be written as
  96. %
  97. %   \parashade{sharpcorners}{$$R_{\mu\nu}-{1\over2}g_{\mu\nu}R = kT_{\mu\nu}$$}
  98. %
  99. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  100.  
  101. \newbox\graybox
  102. \newdimen\xgrayspace
  103. \newdimen\ygrayspace
  104.  
  105. %----------------------------------------------------------------------------
  106. %
  107. % The following \TeX code was based on previous work by
  108. %
  109. %            Je'ro^me Maillot, [email protected]
  110. %
  111. %----------------------------------------------------------------------------
  112. %
  113. % Use the following for one or more words within a line.
  114. %
  115. %MAR-added ability for optional argument for user to set grayscale
  116. \def\textshade{\@ifnextchar[{\@textshade}{\@textshade[0.95]}}
  117. \def\@textshade[#1]#2#3{%
  118.     \xgrayspace=4pt%
  119.     \ygrayspace=4pt%
  120.     \def\grayshade{#1}%
  121.     \def\outlineboxwidth{1}%
  122.     \def\theradius{5}%
  123.     \setbox\graybox=\hbox{\surroundboxa{#3}}%
  124.     \hbox{%
  125.     \hbox to 0pt{%
  126.     \special{"gsave newpath 0 0 moveto                                %
  127.         0                                    1 copy /xmin exch store  %
  128.         \number\dp\graybox \space -65536 div 1 copy /ymin exch store  %
  129.         \number\wd\graybox \space  65536 div 1 copy /xmax exch store  %
  130.         \number\ht\graybox \space  65536 div 1 copy /ymax exch store  %
  131.         \theradius\space                            /radius exch store
  132.         \outlineboxwidth\space                      /linewidth exch store
  133.         \grayshade\space                            /grayshade exch store
  134.         #2 grestore}}%
  135.     \box\graybox}}%
  136. %
  137. % Use the following for paragraphs.
  138. %
  139. %MAR-added ability for optional argument for user to set grayscale
  140. \def\parashade{\@ifnextchar[{\@parashade}{\@parashade[0.95]}}
  141. %MAR-added \long to allow multiple paragraphs in one shaded block
  142. \long\def\@parashade[#1]#2#3{%
  143.     \xgrayspace=3pt%
  144.     \ygrayspace=3pt%
  145.     \def\grayshade{#1}%
  146.     \def\outlineboxwidth{0}%
  147.     \def\theradius{10}%
  148.     \def\thevskip{15pt}%
  149.     \setbox\graybox=\hbox{\surroundboxb{#3}}%
  150.     \vskip\thevskip
  151.     \hbox{%
  152.     \hbox to 0pt{%
  153.     \special{"gsave newpath 0 0 moveto                                %
  154.         0                                    1 copy /xmin exch store  %
  155.         \number\dp\graybox \space -65536 div 1 copy /ymin exch store  %
  156.         \number\wd\graybox \space  65536 div 1 copy /xmax exch store  %
  157.         \number\ht\graybox \space  65536 div 1 copy /ymax exch store  %
  158.         \theradius\space                            /radius exch store
  159.         \outlineboxwidth\space                      /linewidth exch store
  160.         \grayshade\space                            /grayshade exch store
  161.         #2 grestore}}%
  162.      \box\graybox}%
  163.      \vskip\thevskip%
  164. }%
  165. %----------------------------------------------------------------------------
  166. %
  167. % A pair of box macros. Each builds a slightly oversized box
  168. % containing the text. The text is centred both in the vertical
  169. % horizontal directions.
  170. %
  171. % Use the following for one or more words within a line.
  172. %
  173. \long\def\surroundboxa#1{\leavevmode\hbox{\vtop{%
  174. \vbox{\kern\ygrayspace%
  175. \hbox{\kern\xgrayspace#1%
  176.       \kern\xgrayspace}}\kern\ygrayspace}}}
  177. %
  178. % Use the following for a paragraphs.
  179. %
  180. \long\def\surroundboxb#1{\leavevmode\hbox{\vtop{%
  181. \vbox{\kern\ygrayspace%
  182. \hbox{\kern\xgrayspace\vbox{\advance\hsize-2\xgrayspace#1}%
  183.       \kern\xgrayspace}}\kern\ygrayspace}}}
  184. %----------------------------------------------------------------------------
  185. %
  186. % Here are some simple PostScript routines.
  187. %
  188. % The TeX command \PScommands must be called before any of the
  189. % shading routines can be used.
  190. %
  191. \long\def\PScommands{\special{! TeXDict begin
  192. %
  193. /sharpbox{%
  194.            newpath
  195.            xmin ymin moveto
  196.            xmin ymax lineto
  197.            xmax ymax lineto
  198.            xmax ymin lineto
  199.            xmin ymin lineto
  200.            closepath
  201.           }bind def
  202. %
  203. /roundbox{%
  204.            newpath
  205.            xmin radius add ymin moveto
  206.            xmax ymin xmax ymax radius arcto
  207.            xmax ymax xmin ymax radius arcto
  208.            xmin ymax xmin ymin radius arcto
  209.            xmin ymin xmax ymin radius arcto 16 {pop} repeat
  210.           closepath
  211.          }bind def
  212. %
  213. /sharpcorners{%
  214.                sharpbox gsave grayshade setgray fill grestore
  215.                linewidth setlinewidth stroke
  216.               }bind def
  217. %
  218. /plainbox{%
  219.            sharpbox grayshade setgray fill
  220.           }bind def
  221. %
  222. /roundcorners{%
  223.                roundbox gsave grayshade setgray fill grestore
  224.                linewidth setlinewidth stroke
  225.               }bind def
  226. %
  227. end}%                   Closes dictionnary
  228. }%
  229.  
  230. \PScommands
  231.  
  232. \endinput
Add Comment
Please, Sign In to add comment