Advertisement
Guest User

FixSmallCaps.sty

a guest
Mar 23rd, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Latex 3.94 KB | None | 0 0
  1. % FixSmallCaps.sty
  2. %%%%%%%%%%%%%%
  3. % FROM: http://tex.stackexchange.com/a/262596
  4. %
  5. % Additional: http://tex.stackexchange.com/a/70240
  6. %%%%%%%%%%%%%%
  7.  
  8.  
  9. \ProvidesPackage{FixSmallCaps}
  10. %[2017-03-23, Provides fake smallcaps ]
  11. %%%%%%%%%%%%%%
  12. % Fix Smallcaps in fonts that does not have it.
  13. %%%%%%%%%%%%%%
  14. % Usage:
  15. % \usepackage{FixSmallCaps}
  16. %%%%%%%%%%%%%%
  17. % Qirks:
  18. % * Problem with using other enviorments inside this.
  19. % * teletext (textt) does not work as it should. (it is not
  20. %   mono-spaced).
  21. %%%%%%%%%%%%%%
  22. % Background:
  23. % When dealing with fonts that do not have small caps
  24. % it can be a hassle to use different text sizes for
  25. % at different points in words to mimic small caps.
  26. %
  27. % This package redefines the behaviour of \textsc{}
  28. % to mimic the small caps in fonts that do not have
  29. % it, by scaling the lower case letters by to a factor
  30. % of 0.75 of the original size and applys \uppercase.
  31. %%%%%%%%%%%%%%
  32. % NO COPYRIGHT
  33. %%%%%%%%%%%%%%
  34.  
  35. \RequirePackage{xstring}
  36. \RequirePackage{forloop}
  37. \RequirePackage{relsize}
  38. \RequirePackage{adjustbox}
  39.  
  40. \newcounter{sccounter}
  41. \newcounter{tempStringLength}
  42.  
  43.  
  44. \renewcommand{\textsc}[1]{%
  45.     % this \betterfakesc command requires these two packages:
  46.     %   xstring
  47.     %   forloop
  48.     %
  49.     % First, we obtain the length of the input string.
  50.     \StrLen{#1}[\stringLength]%
  51.     %
  52.     % Our main forloop will be using a condition of “while less than \stringLength”,
  53.     % so we’ll need to increase \stringLength by 1 so the forloop will be able to iterate
  54.     % over the entire string. we’ll use a temporary counter tempStringLength to make
  55.     % this increase. That’s what the next three lines are about.
  56.     \setcounter{tempStringLength}{\stringLength}%
  57.     \addtocounter{tempStringLength}{1}%
  58.     \def\stringLength{\arabic{tempStringLength}}%
  59.     %
  60.     % Here is our main loop. We iterate over the characters in the input string,
  61.     % and the currentLetter is compared to the case rules we have defined. Basically
  62.     % if the currentLetter is any of the lowercase a-z letters, then we apply a
  63.     % “fake small caps” effect to it and output it.
  64.     \forloop[1]{sccounter}{1}{\value{sccounter}<\stringLength}{%
  65.         \StrChar{#1}{\value{sccounter}}[\currentLetter]%
  66.         %
  67.         \IfEqCase*{\currentLetter}{%
  68.           % The lines below are the rules. Obviously more could be added.
  69.           {a}{{\uppercase{\relscale{0.75}a}}}%
  70.           {b}{{\uppercase{\relscale{0.75}b}}}%
  71.           {c}{{\uppercase{\relscale{0.75}c}}}%
  72.           {d}{{\uppercase{\relscale{0.75}d}}}%
  73.           {e}{{\uppercase{\relscale{0.75}e}}}%
  74.           {f}{{\uppercase{\relscale{0.75}f}}}%
  75.           {g}{{\uppercase{\relscale{0.75}g}}}%
  76.           {h}{{\uppercase{\relscale{0.75}h}}}%
  77.           {i}{{\uppercase{\relscale{0.75}i}}}%
  78.           {j}{{\uppercase{\relscale{0.75}j}}}%
  79.           {k}{{\uppercase{\relscale{0.75}k}}}%
  80.           {l}{{\uppercase{\relscale{0.75}l}}}%
  81.           {m}{{\uppercase{\relscale{0.75}m}}}%
  82.           {n}{{\uppercase{\relscale{0.75}n}}}%
  83.           {o}{{\uppercase{\relscale{0.75}o}}}%
  84.           {p}{{\uppercase{\relscale{0.75}p}}}%
  85.           {q}{{\uppercase{\relscale{0.75}q}}}%
  86.           {r}{{\uppercase{\relscale{0.75}r}}}%
  87.           {s}{{\uppercase{\relscale{0.75}s}}}%
  88.           {t}{{\uppercase{\relscale{0.75}t}}}%
  89.           {u}{{\uppercase{\relscale{0.75}u}}}%
  90.           {v}{{\uppercase{\relscale{0.75}v}}}%
  91.           {w}{{\uppercase{\relscale{0.75}w}}}%
  92.           {x}{{\uppercase{\relscale{0.75}x}}}%
  93.           {y}{{\uppercase{\relscale{0.75}y}}}%
  94.           {z}{{\uppercase{\relscale{0.75}z}}}%
  95.           {å}{{\uppercase{\relscale{0.75}å}}}%
  96.           {ä}{{\uppercase{\relscale{0.75}ä}}}%
  97.           {ö}{{\uppercase{\relscale{0.75}ö}}}%
  98.           {ü}{{\uppercase{\relscale{0.75}ü}}}%
  99.         }%
  100.         % if our \currentLetter isn’t any of the letters we have rules for,
  101.         % then just output it now
  102.         [{\currentLetter}]%
  103.     }%
  104. }%
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement