Skip to content

Commit 2213231

Browse files
committed
added optional height for trinket
1 parent 0d1bb90 commit 2213231

4 files changed

Lines changed: 17 additions & 16 deletions

File tree

htmlonly

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
{}
6363

6464
% interactive code listing
65-
\lstnewenvironment{trinket}[1]
65+
\lstnewenvironment{trinket}[2][400]
6666
{}
6767
{}
6868

latexonly

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
{\endminipage}
109109

110110
% interactive code listing
111-
\lstnewenvironment{trinket}[1]
111+
\lstnewenvironment{trinket}[2][400]
112112
{\minipage{\linewidth}}
113113
{\endminipage}
114114

thinkjava.tex

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,8 @@ \section{The hello world program}
561561
% more precise, but also to reduce the number of times ``print'' appears,
562562
% which is a lot!
563563

564-
\begin{trinket}{Hello.java}
564+
% height = 130 + 15 * num_lines
565+
\begin{trinket}[235]{Hello.java}
565566
public class Hello {
566567

567568
public static void main(String[] args) {
@@ -651,7 +652,7 @@ \section{Displaying strings}
651652
You can put as many statements as you like in \java{main}.
652653
For example, to display more than one line of output:
653654

654-
\begin{trinket}{Hello.java}
655+
\begin{trinket}[250]{Hello.java}
655656
public class Hello {
656657

657658
public static void main(String[] args) {
@@ -679,7 +680,7 @@ \section{Displaying strings}
679680
\java{System.out.println} appends a special character, called a {\bf newline}, that moves to the beginning of the next line.
680681
If you don't want a newline at the end, you can use \java{print} instead of \java{println}:
681682

682-
\begin{trinket}{Goodbye.java}
683+
\begin{trinket}[235]{Goodbye.java}
683684
public class Goodbye {
684685

685686
public static void main(String[] args) {
@@ -700,7 +701,7 @@ \section{Escape sequences}
700701
It is possible to display multiple lines of output in just one line of code.
701702
You just have to tell Java where to put the line breaks.
702703

703-
\begin{trinket}{Hello.java}
704+
\begin{trinket}[220]{Hello.java}
704705
public class Hello {
705706

706707
public static void main(String[] args) {
@@ -775,7 +776,7 @@ \section{Formatting code}
775776
But most other spaces are optional.
776777
For example, this program is legal:
777778

778-
\begin{trinket}{Goodbye.java}
779+
\begin{trinket}[220]{Goodbye.java}
779780
public class Goodbye {
780781
public static void main(String[] args) {
781782
System.out.print("Goodbye, ");
@@ -787,7 +788,7 @@ \section{Formatting code}
787788
The newlines are optional, too.
788789
So we could just write:
789790

790-
\begin{trinket}{Goodbye.java}
791+
\begin{trinket}[175]{Goodbye.java}
791792
public class Goodbye { public static void main(String[] args)
792793
{ System.out.print("Goodbye, "); System.out.println
793794
("cruel world");}}
@@ -1661,7 +1662,7 @@ \section{Types of errors}
16611662
Error messages from the compiler usually indicate where in the program the error occurred, and sometimes they can tell you exactly what the error is.
16621663
As an example, let's get back to the hello world program from Section~\ref{hello}.
16631664

1664-
\begin{trinket}{Hello.java}
1665+
\begin{trinket}[235]{Hello.java}
16651666
public class Hello {
16661667

16671668
public static void main(String[] args) {
@@ -1753,7 +1754,7 @@ \section{Types of errors}
17531754
Instead, it will do exactly what you told it to do.
17541755
For example, here is a version of the hello world program with a logic error:
17551756

1756-
\begin{trinket}{Hello.java}
1757+
\begin{trinket}[235]{Hello.java}
17571758
public class Hello {
17581759

17591760
public static void main(String[] args) {
@@ -2833,7 +2834,7 @@ \section{Adding new methods}
28332834
You have probably guessed by now that you can define more than one method in a class.
28342835
Here's an example:
28352836

2836-
\begin{trinket}{NewLine.java}
2837+
\begin{trinket}[310]{NewLine.java}
28372838
public class NewLine {
28382839

28392840
public static void newLine() {
@@ -3008,7 +3009,7 @@ \section{Parameters and arguments}
30083009
The parameter list indicates what arguments are required.
30093010
The following class shows an example:
30103011

3011-
\begin{trinket}{PrintTwice.java}
3012+
\begin{trinket}[295]{PrintTwice.java}
30123013
public class PrintTwice {
30133014

30143015
public static void printTwice(String s) {
@@ -3128,7 +3129,7 @@ \section{Stack diagrams}
31283129

31293130
Pulling together the code fragments from the previous section, here is a complete class definition:
31303131

3131-
\begin{trinket}{PrintTime.java}
3132+
\begin{trinket}[340]{PrintTime.java}
31323133
public class PrintTime {
31333134

31343135
public static void printTime(int hour, int minute) {

trinket/trinket.tex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@
7272

7373
% custom HTML for Trinket publisher tools
7474
% see http://hevea.inria.fr/doc/manual018.html
75-
\newenvironment{trinket}[1]
76-
{\@print{<script type="text/javascript">(function(d,l,s,i,c){function n(e){e=e.nextSibling;return (!e||e.nodeType!=3)?e:n(e);};function r(f){/in/.test(d.readyState) ? setTimeout(function(){r(f);},9):f()};l=d.getElementsByTagName('script');s=l[l.length-1];r(function(){i=n(s),c=n(i);i.setAttribute('data-src','https://trinket.io/tools/1.0/jekyll/embed/java#code='+encodeURIComponent(c.nodeValue.replace(/^\s+|\s+$/g,'')));});})(document)</script><iframe width="100\%" height="400" frameborder="0" marginwidth="0" marginheight="0" class="lazyload" allowfullscreen></iframe><!--}
77-
[[[[ #1 ]]]]\rawhtml}
75+
\newenvironment{trinket}[2][400]
76+
{\@print{<script type="text/javascript">(function(d,l,s,i,c){function n(e){e=e.nextSibling;return (!e||e.nodeType!=3)?e:n(e);};function r(f){/in/.test(d.readyState) ? setTimeout(function(){r(f);},9):f()};l=d.getElementsByTagName('script');s=l[l.length-1];r(function(){i=n(s),c=n(i);i.setAttribute('data-src','https://trinket.io/tools/1.0/jekyll/embed/java#code='+encodeURIComponent(c.nodeValue.replace(/^\s+|\s+$/g,'')));});})(document)</script><iframe width="100\%" height="}#1\@print{" frameborder="0" marginwidth="0" marginheight="0" class="lazyload" allowfullscreen></iframe><!--}
77+
[[[[ #2 ]]]]\rawhtml}
7878
{\endrawhtml\@print{-->}}
7979
8080
% inline syntax formatting

0 commit comments

Comments
 (0)