hplgit / doconce

Lightweight markup language - document once, include anywhere
http://hplgit.github.io/doconce/doc/web/index.html
Other
309 stars 60 forks source link

Placement of solution in running text #194

Closed andre-massing closed 4 years ago

andre-massing commented 4 years ago

I observed that whenever I add a solution to an exercise that the solution will not be presented in place but rather be moved to the end of the current subsection. Is this the intended behavior?

Here is a simple example which illustrate that behavior:

TITLE: Solution, where do you go?
AUTHOR: André Massing
DATE: today

======= Section heading (h1) =======

===== Exercise: Solution placement =====
Where does doconce place the solution in your document?

!bsol
It seems to be at the end of the current section
!esol

Even I add more text here.

=== Paragraph ===
And even if I add a new paragraph

===== Subsection heading (h2) =====
But a new Subsection seems to force the print of the solution.

The solution is not placed right after the exercise, but rather right before Subsection heading (h2)

Is is possible to change this behavior easily? In my lectures I often give the students some small exercises to work on, and then I would like to present solution and continue with material without being forced to open up a new section.

Best, Andre

aless80 commented 4 years ago

An exercise section is ended on a few conditions, see the code below. I suggest you use a !split in the line after the end of the solution (!esol).

# End of exercise? Either 1) new (sub)section with at least ===,
# 2) !split, or 3) end of file
if line_no == len(lines) - 1:  # last line?
    exer_end = True
elif inside_exer and lines[line_no+1].startswith('!split'):
    exer_end = True
elif inside_exer and lines[line_no+1].startswith('====='):
    exer_end = True
elif inside_exer and option('sections_down') and lines[line_no+1].startswith('==='):
    exer_end = True
andre-massing commented 4 years ago

Hi Alessandro,

ah indeed, nice suggestion, that fixed my problem. Thanks a lot!

Best, Andre