Guest User

Untitled

a guest
Aug 15th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.59 KB | None | 0 0
  1. documentclass{article}
  2.  
  3. usepackage{lipsum}
  4.  
  5. makeatletter
  6. endlinechar=-1
  7.  
  8. newcountshortvbox@lines
  9.  
  10. % #1: Number of lines in the final box
  11. % #2: Width of the box
  12. % #3: Text
  13. longdefshortvbox#1#2#3{
  14. begingroup
  15. setbox0=vtop{hsize=#2 #3par}
  16. setbox2=vtop{unvcopy0shortvbox@{#1}C}
  17. setbox2=vtop{unvcopy0shortvbox@{#1}B}
  18. vtop{hsize=#2unvbox1parnoindentstrutldotspar}
  19. endgroup
  20. }
  21.  
  22. % #1: number of lines to reassemble
  23. % #2: C = count lines only, otherwise also build box
  24. defshortvbox@#1#2{
  25. begingroup
  26. globalsetbox1=vtop{}
  27. if#2C
  28. globalshortvbox@lines=0relax
  29. fi
  30. loop
  31. count1=lastnodetype
  32. ifnumcount1=1relax % hbox
  33. setbox10=lastbox
  34. globaladvanceshortvbox@lines by if#2C 1else -1fi
  35. fi
  36. ifnumcount1=11relax % glue
  37. skip10=lastskip
  38. unskip
  39. fi
  40. ifnumcount1=13relax % penalty
  41. count10=lastpenalty
  42. unpenalty
  43. fi
  44. % message{lastnodetype=thecount1}
  45. edef@stop{
  46. ifnumcount1<0 0else
  47. ifnumcount1=1 1else
  48. ifnumcount1=11 1else
  49. ifnumcount1=13 1else
  50. 0% stop early if we don't know how to handle the last node
  51. fifififi
  52. }
  53. if@stop0
  54. else
  55. if#2Celse
  56. globalsetbox1=vtop{
  57. ifnumshortvbox@lines<#1relax
  58. ifnumcount1=1relax % hbox
  59. box10
  60. fi
  61. ifnumcount1=11relax % glue
  62. vskipskip10
  63. fi
  64. ifnumcount1=13relax % penalty
  65. penaltycount10
  66. fi
  67. unvbox1
  68. fi
  69. }
  70. fi
  71. repeat
  72. endgroup
  73. }
  74.  
  75. endlinechar=`^^M
  76. makeatother
  77.  
  78. begin{document}
  79.  
  80. fbox{shortvbox{7}{5cm}{What if I have got a (possibly long) text that I would like to typeset in a 5cm wide minipage, textbf{ragged right}, so that it uses at most 6 lines?
  81. vskip2ex
  82. Basically, I would just like to ask LaTeX to typeset a piece of text so that we add line breaks as usual at most 5 times, and then the last line is truncated (with some kind of a truncation marker such as texttt{"..."}) if needed.}}
  83. hskip1em
  84. fbox{shortvbox{4}{5cm}{raggedright What if I have got a (possibly long) text that I would like to typeset in a 5cm wide minipage, textbf{ragged right}, so that it uses at most 6 lines?
  85. vskip2ex
  86. Basically, I would just like to ask LaTeX to typeset a piece of text so that we add line breaks as usual at most 5 times, and then the last line is truncated (with some kind of a truncation marker such as texttt{"..."}) if needed.}}
  87.  
  88. shortvbox{4}{linewidth}{lipsum}
  89.  
  90. end{document}
Add Comment
Please, Sign In to add comment