ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* getting line numbers
@ 2021-09-03 10:58 Thierry Horsin via ntg-context
  2021-09-03 12:16 ` Hans Hagen via ntg-context
  2021-09-03 13:53 ` Aditya Mahajan via ntg-context
  0 siblings, 2 replies; 9+ messages in thread
From: Thierry Horsin via ntg-context @ 2021-09-03 10:58 UTC (permalink / raw)
  To: ntg-context; +Cc: Thierry Horsin

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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 9+ messages in thread
[parent not found: <mailman.418.1630685069.1197.ntg-context@ntg.nl>]

end of thread, other threads:[~2021-09-05 10:26 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-03 10:58 getting line numbers Thierry Horsin via ntg-context
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

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).