ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Thierry Horsin via ntg-context <ntg-context@ntg.nl>
To: ntg-context@ntg.nl
Cc: Thierry Horsin <horsin@free.fr>
Subject: getting line numbers
Date: Fri, 3 Sep 2021 12:58:13 +0200	[thread overview]
Message-ID: <20210903105813.bw5hn5ak7k6ttyob@thierry-Latitude-5300> (raw)

Hi everybody

Is there a way to have an automatic access to the current line number of a specific place inside a tex file ? To be more precise, here is what I would like to do.

I am currently trying to have some automatic external compilation by g++ of some portion of my tex file as in the following example below. \startC \stopC defines a framed part of text written between lines 538 and 549. Of course, if I add something before or inbetween my framed code, 538 and/or 549 will change. Thus I would like to get these two numbers automatically.

Thank you.
Thierry

\startC
#include <iostream>

using namespace std;
int mysum(int,int); int a; int b;
int main () { a=2; b=9;
  cout << mysum(a,b) << endl;
  return 0; 
        }
int mysum(int a, int b)
{ return a+b; }
\stopC

\startluacode
myout = io.open("test.cpp", "w")
myin = io.open(tex.jobname..".tex", "r")
local n=0
for line in myin:lines() do
n=n+1
if n>539 and n<550 then
    myout:write(line.."\n")
 end   
end
myout:close()
myin:close()
os.execute("g++ -o test test.cpp")
os.execute("./test > tmp")
local file=assert(io.open("tmp","r"))
local t = file:read("*all")
tex.print(t)
\stopluacode





___________________________________________________________________________________
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
___________________________________________________________________________________

             reply	other threads:[~2021-09-03 10:58 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-03 10:58 Thierry Horsin via ntg-context [this message]
2021-09-03 12:16 ` Hans Hagen via ntg-context
2021-09-03 12:20   ` Thierry Horsin via ntg-context
2021-09-03 13:53 ` Aditya Mahajan via ntg-context
2021-09-03 16:26   ` Hans Hagen via ntg-context
2021-09-05 10:26     ` Fabrice Couvreur via ntg-context
     [not found] <mailman.418.1630685069.1197.ntg-context@ntg.nl>
2021-09-04  7:01 ` thierry horsin via ntg-context
2021-09-04  8:35   ` Hans Hagen via ntg-context
2021-09-04 10:18     ` Thierry Horsin via ntg-context

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210903105813.bw5hn5ak7k6ttyob@thierry-Latitude-5300 \
    --to=ntg-context@ntg.nl \
    --cc=horsin@free.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).