Source syntax help

Basic syntax

e-Labsheet uses Markdown. For details, see Markdown's syntax. Other tabs describe e-Labsheet additional tags.

Source code

Enclose source code in ::elab:begincode and ::elab:endcode, and mark blanks in {{ }}. See an example below.

Consider the following code:

::elab:begincode
x = int(raw_input())
print {{x + 100}}
::elab:endcode

Consider the following code:

x = int(raw_input())
print 

Line numbering can be turned on by using a lineno=True directive.

Consider the following code:

::elab:begincode lineno=True
x = int(raw_input())
print {{x + 100}}
::elab:endcode

Consider the following code:

1: x = int(raw_input())
2: print 

A code block can be customized by specifying directives. The following directives are currently supported:

  • hidden (default False) controls whether the block will show up when a student is working on the task. However, the code block will still be included in the automatic grading process.
  • highlight (default True) enables syntax highlighting on the source code.
  • lineno (default False) enables line numbering on the source code.
  • excluded (default False) specifies whether the code block is to be excluded from the code compilation. The code block will be displayed no matter what the value is.
  • blank (default False) specifies whether the code block is to be made entirely blank.
  • language (default None) explicitly specifies the language for which the code segment will be highlighted. If this parameter is None and highlight is True, the code segment will be highlighted based on the language setting at the task level.

Source hiding and exclusion

Each individual line inside a ::elab:begincode and ::elab:endcode block can be marked hidden from viewing or excluded from the source by prefixing the line with the directives ::elab:hide and ::elab:exclude, respectively.

For example, the following markdown code

::elab:begincode
def main():
::elab:exclude     x = randint(0,100)
::elab:hide     x = int(raw_input())
    print x
::elab:endcode
will be displayed in the task view as
def main():
    x = randint(0,100)
    print x
However, the actual source to be seen and executed by the grader is
def main():
    x = int(raw_input())
    print x

Extra build and run flags

Extra build and run flags can be specified using ::elab:buildflags and ::elab:runflags, respectively.

Build flags will be inserted into the build command, i.e., when compiling the code. For example, if the following line is used in a C# task,

::elab:buildflags -reference:mylib.dll

then the C# compiler, gmcs, will be called with the option -reference:mylib.dll when compiling the model code and code submitted by students.

Run flags will be inserted into the command that runs the code. For example, if the following line is used in a Java task,

::elab:runflags -Dmy.property="hello"

then the Java interpreter, java will be called with the option -Dmy.property="hello" when running the code.

Test cases

Enclose each input in ::elab:begintest and ::elab:endtest. For example,

::elab:begintest
10
::elab:endtest

The system will generate the output from the solution in the source. For the above input, the output generated is 110.

Manual grading

The system also support questions that require manual grading. Any blanks outside the code tags will be treated as blanks for manual grading. The format is {{[score]solution}}. For example

Python is a {{[10] dynamic}} language.

The score part is optional. If omitted, the default value of 1 will be used. E.g.,

Python is a {{dynamic}} language.

Automatically gradable answers

Any manual grading blank with an answer surrounded by ! is treated as an automatically gradable answer. For example,

There are {{!8!}} bits in one byte.

Each student submission will be checked against the provided answer. The full score will be assigned if matched, or zero will be given otherwise. The automatically assigned score can be changed manually if needed.

Equations

An equation can be created by putting LaTeX code inside a pair of \( and \) for an inline equation, or \[ and \] for an equation that will be displayed on its own line. The equation will be rendered by MathJax javascript library.

Examples:

The root of the quadratic 
equation \(ax^2+bx+c = 0\) is: 
\[
    x = -b\pm\frac{\sqrt{b^2-4ac}}{2a}.
\]

The root of the quadratic equation \(ax^2+bx+c = 0\) is: \[ x = -b\pm\frac{\sqrt{b^2-4ac}}{2a}. \]

Java-specific source syntax

Since Java is very strict in source file names and the system is not good enough to figure them all out by itself, you should help it. The system supports many source files and lets the user specify the main class to be called. It can also infer class name from the first source file name.

There are two ways to include many source files for Java.

1. Inside source field of Task. (This is required.)

Users must specify the source file names in the source by placing the following options (as comments) inside the elab::begincode - elab::endcode tags.

  • Specifying source file name:

    // elab-source: filename (with path)
    
  • Specifying main class:

    // elab-mainclass:  mainclass.Name
    

The source field in task shall be broken into many source files at places where the elab-source options are. The content before the first option is discarded.

If main class is not specify, the name is derived from the first source filename.

2. As Task supplements.

Users can also add more related source files as the task supplements. All files should be compressed (using zip or gzip) so that to save the original path and file names. The files will be extracted to the sand box directory when the program gets compiled and executed. Then, JavaBuilder will search for all files with .java extension and compile them.

Raw HTML

Quoted from Markdown syntax page:

For any markup that is not covered by Markdown's syntax, you simply use HTML itself. There's no need to preface it or delimit it to indicate that you're switching from Markdown to HTML; you just use the tags.

The only restrictions are that block-level HTML elements -- e.g. <div>, <table>, <pre>, <p>, etc. -- must be separated from surrounding content by blank lines, and the start and end tags of the block should not be indented with tabs or spaces. Markdown is smart enough not to add extra (unwanted) <p> tags around HTML block-level tags.

Therefore, Markdown will produce an HTML block as appear in source if the HTML block is preceded by an empty line. So, be careful when preparing a document containing an HTML block with special Markdown syntax inside such as an answer field.

For example, the following markdown source is processed as desired:

Markdown Source

Fill in the blanks:
<table border="1">
<tr>
  <td>Question 1</td>
  <td>{{answer1}}</td>
</tr>
<tr>
  <td>Question 2</td>
  <td>{{answer2}}</td>
</tr>
</table>
Output

Fill in the blanks:

Question 1
Question 2

However, inserting an empty line right before the table tag may give an undesirable result, as shown:

Markdown Source

Fill in the blanks:
<table border="1"> <tr> <td>Question 1</td> <td>{{answer1}}</td> </tr> <tr> <td>Question 2</td> <td>{{answer2}}</td> </tr> </table>
Output

Fill in the blanks:

Question 1 {{answer1}}
Question 2 {{answer2}}

Embedding Media

Media such as Youtube video may be embedded into a task using the ::elab:embed tag, which must be followed by a media argument to specify the media type and identifier. Media embedded via ::elab:embed tag will automatically be rendered with a feedback dialog attached so that students can provide comments and ratings for the media in the embedding task.

For example, the following line embeds the Youtube video with video ID PfCFzezMLxM into the task.

::elab:embed media="youtube:PfCFzezMLxM"

Note that embedded media will not show up in the task editing page. Save the task first and view the result in the task test page.