[NTG-context] Django: using ConTeXT mkiv to output PDF

2018-01-24 Thread kaddour kardio
i have a small Django app  to
manage my patients data, and use LaTeX to output reports. It consists un a
*parent* model called Patients and child models Consultation , StressEcho and
so on. With LaTex this works without problems

def courrier_pdf(request, pk2, pk1):
entry = Courrier.objects.get(pk=pk2)
source = Patient.objects.get(pk=pk1)
context = dict({'courrier': entry, 'patient': source})#buffer =
BytesIO()template = get_template('courrier/courrier.tex')
rendered_tpl = template.render(context,
request).encode('utf-8')#Python3 only. For python2 check out the
docs!with tempfile.TemporaryDirectory() as tempdir:
  # Create subprocess, supress output with PIPE and
  # run latex twice to generate the TOC properly.
  # Finally read the generated pdf.
for i in range(2):
process = Popen(
['xelatex', '-output-directory', tempdir],
stdin=PIPE,
stdout=PIPE,
)
process.communicate(rendered_tpl)
with open(os.path.join(tempdir, 'texput.pdf'), 'rb') as f:
pdf = f.read()
r = HttpResponse(content_type='application/pdf')
r.write(pdf)return r

i tried with this view in order to use ConTeXT but without success

def courrier_mkiv(request, pk2, pk1):

entry = Courrier.objects.get(pk=pk2)
cource = Patient.objects.get(pk=pk1)
context = dict({'courrier': entry, 'patient': cource})# buffer =
BytesIO()template = get_template('courrier/courrier.mkiv')
rendered_tpl = template.render(context, request).encode('utf-8')with
tempfile.TemporaryDirectory() as tempdir:
process = Popen(['context', '--result', tempdir],
stdin=PIPE,
stdout=PIPE,
)
process.communicate(rendered_tpl)
with open(os.path.join(tempdir, 'textput.pdf'), 'rb') as f:
pdf = f.read()
r = HttpResponse(content_type='application/pdf')
r.write(pdf)return r

My feeling is that the problem is in the workspace since i get logfiles in
the root of my app Here is log file from ConTeXT:

open source > level 1, order 1, name '/home/kaddour/context/tex/texmf-
context/tex/context/base/mkiv/cont-yes.mkiv'
system  >
system  > ConTeXt  ver: 2018.01.04 17:37 MKIV beta  fmt:
2018.1.4  int: english/english
system  >
system  > 'cont-new.mkiv' loaded
open source > level 2, order 2, name '/home/kaddour/context/tex/texmf-
context/tex/context/base/mkiv/cont-new.mkiv'
close source> level 2, order 2, name '/home/kaddour/context/tex/texmf-
context/tex/context/base/mkiv/cont-new.mkiv'
system  > files > jobname 'tmpy82c5j7i', input
'/tmp/tmpy82c5j7i', result 'tmpy82c5j7i'
fonts   > latin modern fonts are not preloaded
languages   > language 'en' is active

tex error   > tex error on line 8 in file /home/kaddour/context/tex/texmf-
context/tex/context/base/mkiv/cont-yes.mkiv: ! I can't find file
`/tmp/tmpy82c5j7i'.

l.8 }

I tried this in my view

os.chdirw(tempdir)

just before process without success.

My guess is that ConTeXT option --result= does not behave exactly like
LaTeX's -output-directoryAny help is welcome i really need ConTeXT for my
work and this problem is driving me mad!

-- 
Dr YAHYAOUI Mohamed Kaddour, cardiologue -- Clinique KARDIA.
___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___

Re: [NTG-context] chapter setup with subtitle in margin

2018-01-24 Thread Mikael P. Sundqvist
On Wed, Jan 24, 2018 at 11:00 PM, Henning Hraban Ramm 
wrote:

> Am 2018-01-24 um 19:25 schrieb Aditya Mahajan :
>
> > On Wed, 24 Jan 2018, Henning Hraban Ramm wrote:
> >
> >> Am 2018-01-23 um 22:31 schrieb Henning Hraban Ramm :
> >>
> >>> I have this nice/complicated chapter setup (see attachments):
> >>> Three problems I cannot get rid of:
> >>>
> >>> - There’s always an indent in front of the title (red box); it should
> not.
> >>> - The subtitle should start on the same line as the main title.
> >>> - The subtitle should have an appropriate line spacing.
> >>
> >> I could solve the subtitle placement with layers.
> >>
> >> But the chapter title still has this indent. :-(
> >
> > Untested, but you have two spurious spaces in your code
> >
> > \define[2]\ChapterCmd{%
> >  \inouter{\framed[frame=off,align=flushleft]{%
> >%\startlinecorrection
> >\switchtobodyfont[rm,12pt] % <-- Here. Remove space before %
> >\structureuservariable{subtitle}}%
> >%\stoplinecorrection
> >}% << HERE: % was missing
> >  \framed[width=\textwidth,frame=off,align=flushleft]{\ChapterTitleFont
> #2}
> > }
>
> Thank you, but those existed only in an old version.
> Current is:
>
> \define[2]\ChapterCmd{%
>   
> \framed[width=\textwidth,frame=off,align=flushleft,style=\ChapterTitleFont]{#2}%
> without framed it’s a hbox?
>   \setlayerframed[rightmargin]%
>   [frame=off,width=\outermarginwidth,y=0mm,setups=
> Subtitle,align=flushleft]%
>   {\structureuservariable{subtitle}}%
> }
>
> And the indent is still there.
>
>
> Greetlings, Hraban
> ---
> http://www.fiee.net
> http://wiki.contextgarden.net
> GPG Key ID 1C9B22FD
>
> 
> ___
> If your question is of interest to others as well, please add an entry to
> the Wiki!
>
> maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/
> listinfo/ntg-context
> webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
> archive  : https://bitbucket.org/phg/context-mirror/commits/
> wiki : http://contextgarden.net
> 
> ___
>

I think you can get rid of that horizontal space by adding "offset=overlay"
to the framed environment used in your \ChapterCmd.

/Mikael
___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___

Re: [NTG-context] structureuservariable in ToC

2018-01-24 Thread Henning Hraban Ramm
Am 2018-01-24 um 19:18 schrieb Wolfgang Schuster :

>> Henning Hraban Ramm 24. Januar 2018 um 08:51
>> 
>> Thank you, now I have:
>> 
>> \define[1]\ChapterTocEntry{%
>> \doifnotempty{\structurelistuservariable{author}}{\structureuservariable{author}\crlf
>>  }%
>> #1%
>> \doifnotempty{\structurelistuservariable{subtitle}}{\crlf\structureuservariable{subtitle}}}
>> 
>> But author/subtitle still don’t show up in the ToC.
> Use the \doiftext check or replace \structurelistuservariable (which is never 
> empty because
> it is tagged) with \rawstructurelistuservariable (which isn’t tagged and 
> contains only the content
> of the variable).

Thank you so much! You saved my day/night/toc ;)


Grüßlinge, Hraban
---
http://www.fiee.net
http://wiki.contextgarden.net
GPG Key ID 1C9B22FD

___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___

Re: [NTG-context] chapter setup with subtitle in margin

2018-01-24 Thread Henning Hraban Ramm
Am 2018-01-24 um 19:25 schrieb Aditya Mahajan :

> On Wed, 24 Jan 2018, Henning Hraban Ramm wrote:
> 
>> Am 2018-01-23 um 22:31 schrieb Henning Hraban Ramm :
>> 
>>> I have this nice/complicated chapter setup (see attachments):
>>> Three problems I cannot get rid of:
>>> 
>>> - There’s always an indent in front of the title (red box); it should not.
>>> - The subtitle should start on the same line as the main title.
>>> - The subtitle should have an appropriate line spacing.
>> 
>> I could solve the subtitle placement with layers.
>> 
>> But the chapter title still has this indent. :-(
> 
> Untested, but you have two spurious spaces in your code
> 
> \define[2]\ChapterCmd{%
>  \inouter{\framed[frame=off,align=flushleft]{%
>%\startlinecorrection
>\switchtobodyfont[rm,12pt] % <-- Here. Remove space before %
>\structureuservariable{subtitle}}%
>%\stoplinecorrection
>}% << HERE: % was missing
>  \framed[width=\textwidth,frame=off,align=flushleft]{\ChapterTitleFont #2}
> }

Thank you, but those existed only in an old version.
Current is:

\define[2]\ChapterCmd{%
  
\framed[width=\textwidth,frame=off,align=flushleft,style=\ChapterTitleFont]{#2}%
 without framed it’s a hbox?
  \setlayerframed[rightmargin]%
  [frame=off,width=\outermarginwidth,y=0mm,setups=Subtitle,align=flushleft]%
  {\structureuservariable{subtitle}}%
}

And the indent is still there.


Greetlings, Hraban
---
http://www.fiee.net
http://wiki.contextgarden.net
GPG Key ID 1C9B22FD


marginsubtitle.tex
Description: Binary data
___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___

Re: [NTG-context] chapter setup with subtitle in margin

2018-01-24 Thread Aditya Mahajan

On Wed, 24 Jan 2018, Henning Hraban Ramm wrote:


Am 2018-01-23 um 22:31 schrieb Henning Hraban Ramm :


I have this nice/complicated chapter setup (see attachments):
Three problems I cannot get rid of:

- There’s always an indent in front of the title (red box); it should not.
- The subtitle should start on the same line as the main title.
- The subtitle should have an appropriate line spacing.


I could solve the subtitle placement with layers.

But the chapter title still has this indent. :-(


Untested, but you have two spurious spaces in your code

\define[2]\ChapterCmd{%
  \inouter{\framed[frame=off,align=flushleft]{%
%\startlinecorrection
\switchtobodyfont[rm,12pt] % <-- Here. Remove space before %
\structureuservariable{subtitle}}%
%\stoplinecorrection
}% << HERE: % was missing
  \framed[width=\textwidth,frame=off,align=flushleft]{\ChapterTitleFont 
#2}

}

Aditya
___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___

Re: [NTG-context] chapter setup with subtitle in margin

2018-01-24 Thread Henning Hraban Ramm
Am 2018-01-23 um 22:31 schrieb Henning Hraban Ramm :

> I have this nice/complicated chapter setup (see attachments):
> Three problems I cannot get rid of:
> 
> - There’s always an indent in front of the title (red box); it should not.
> - The subtitle should start on the same line as the main title.
> - The subtitle should have an appropriate line spacing.

I could solve the subtitle placement with layers.

But the chapter title still has this indent. :-(


Greetlings, Hraban
---
http://www.fiee.net
http://wiki.contextgarden.net
GPG Key ID 1C9B22FD


marginsubtitle.tex
Description: Binary data
___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___

Re: [NTG-context] structureuservariable in ToC

2018-01-24 Thread Wolfgang Schuster

Henning Hraban Ramm 
24. Januar 2018 um 08:51

Thank you, now I have:

\define[1]\ChapterTocEntry{%
\doifnotempty{\structurelistuservariable{author}}{\structureuservariable{author}\crlf 
}%

#1%
\doifnotempty{\structurelistuservariable{subtitle}}{\crlf\structureuservariable{subtitle}}}

But author/subtitle still don’t show up in the ToC.
Use the \doiftext check or replace \structurelistuservariable (which is 
never empty because
it is tagged) with \rawstructurelistuservariable (which isn’t tagged and 
contains only the content

of the variable).


\define[3]\SectionListCommand
  {\doiftextelse{\structurelistuservariable{test}}{YES}{NO}%
   \endgraf}

% \define[3]\SectionListCommand
%   {\doifsomethingelse{\rawstructurelistuservariable{test}}{YES}{NO}%
%\endgraf}

\setuplist[section][alternative=command,command=\SectionListCommand]

\starttext

\placelist[section]

\startsection[title=X][test=A] \stopsection

\startsection[title=Y] \stopsection

\startsection[title=Z][test=B] \stopsection

\stoptext


Wolfgang
___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___

Re: [NTG-context] structureuservariable in ToC

2018-01-24 Thread Henning Hraban Ramm
Am 2018-01-24 um 16:42 schrieb Wolfgang Schuster :

>> Henning Hraban Ramm 24. Januar 2018 um 08:51
>> 
>> Thank you, now I have:
>> 
>> \define[1]\ChapterTocEntry{%
>> \doifnotempty{\structurelistuservariable{author}}{\structureuservariable{author}\crlf
>>  }%
>> #1%
>> \doifnotempty{\structurelistuservariable{subtitle}}{\crlf\structureuservariable{subtitle}}}
>> 
>> But author/subtitle still don’t show up in the ToC.
> 
> You’re still using the wrong command to print the variables.
> 
> \setuplist --> \structurelistuservariable
> \setuphead --> \structureuservariable

Aaargh, I’m blind, sorry, I changed only half of the occurrencies.

Everything’s ok now, _if_ author and subtitle are defined.

But \structurelistuservariable{something} seems to be never empty in the sense 
of \ifempty - I get those \crlf also for chapters without i.e. where I didn’t 
define those or set them to {}.


Greetlings, Hraban
---
http://www.fiee.net
http://wiki.contextgarden.net
GPG Key ID 1C9B22FD


marginsubtitle.tex
Description: Binary data
___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___

Re: [NTG-context] structureuservariable in ToC

2018-01-24 Thread Wolfgang Schuster



Henning Hraban Ramm 
24. Januar 2018 um 08:51

Thank you, now I have:

\define[1]\ChapterTocEntry{%
\doifnotempty{\structurelistuservariable{author}}{\structureuservariable{author}\crlf 
}%

#1%
\doifnotempty{\structurelistuservariable{subtitle}}{\crlf\structureuservariable{subtitle}}}

But author/subtitle still don’t show up in the ToC.


You’re still using the wrong command to print the variables.

\setuplist --> \structurelistuservariable
\setuphead --> \structureuservariable

Wolfgang
___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___

Re: [NTG-context] Error at \stoplines

2018-01-24 Thread Henning Hraban Ramm
Am 2018-01-23 um 22:42 schrieb Aditya Mahajan :

> On Tue, 23 Jan 2018, Henning Hraban Ramm wrote:
> 
>> Am 2018-01-23 um 10:29 schrieb r.erm...@hccnet.nl:
 in my current project, every time I use \startlines .. \stoplines (for 
 poems), I run into this error:
 structure   > sectioning > chapter @ level 2 : 5.2 -> Example
 tex error   > tex error on line 27 in file ka34/c_example.tex: ! Extra 
 }, or forgotten \endgroup
>>> 1. count the number of \startlines, do this with grep -e '^\\startlines' | 
>>> wc | less
>>> 2. count the number of \stoplines, do this with grep -e ‘^\\stoplines' | wc 
>>> | less
>>> But you probably already thought of this yourself.
>> 
>> That’s not the problem, there are only a few "lines" sections, and of course 
>> I checked these first.
>> I also checked all(?) other \start/stops, braces and brackets - of course I 
>> could have overlooked some, it’s a whole book, but most cases are caught on 
>> their own.
>> 
>> I guess it might be something in my setups, but not in \setuplines, but 
>> don’t know for what I should look, there’s too much...
>> 
>> Which other setups affect \start/stoplines?
> 
> The error could be due to some other mismatched group. Have you tried:
> 
> mtxrun --script concheck filename.tex

Thank you for the reminder, I should use this more often.
Of course it found a few errors, and now the book runs through.
It’s strange that ConTeXt only stopped at \stoplines.


Greetlings, Hraban
---
http://www.fiee.net
http://wiki.contextgarden.net
GPG Key ID 1C9B22FD

___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___