hello:)
I would like to know if in a macro we can use the latex grammar to know for example if we are in an environment or in displaymath etc... to adapt the command to this situation ?
regards Alain
On Sep 21, 2007, at 7:01 PM, Alain Matthes wrote:
hello:)
I would like to know if in a macro we can use the latex grammar to know for example if we are in an environment or in displaymath etc... to adapt the command to this situation ?
If I understand your question, then yes, that's what scope selectors are for.
regards Alain
Haris Skiadas Department of Mathematics and Computer Science Hanover College
Le 22 sept. 07 à 04:18, Charilaos Skiadas a écrit :
On Sep 21, 2007, at 7:01 PM, Alain Matthes wrote:
hello:)
I would like to know if in a macro we can use the latex grammar to know for example if we are in an environment or in displaymath etc... to adapt the command to this situation ?
If I understand your question, then yes, that's what scope selectors are for.
Thanks the idea is "when i'm in an environment like pspicture or tikzpicture" to have a commmand to compile only the code between
begin{tikzpicture} ..... end{tikzpicture}
I know that is possible with emacs and this is very useful if you works with emacs, idem for listings.
Ruby is perhaps the best tool to make that like some examples in the LaTeX Bundle ? Perhaps you know an example more simple ?
Regards Alain
Alain,
Here is a command I wrote to run Python code that is in a lstlisting environment.
Save: Nothing Input: Selected Text or Scope Output: show as tooltip Scope: source.python ------------------------------------------------ #!/usr/bin/env python import sys import string
# find first non-blank line # determine indent # remove indent from rest of the lines. # run the code using doctest
def allWhite(s): allWhite = True count = 0 for ch in s: if ch not in string.whitespace: allWhite = False return count count += 1 if allWhite == True: return -1
prog = sys.stdin.read()
lineList = prog.split('\n') i = 0 nonWhite = allWhite(lineList[i]) while nonWhite < 0: i = i + 1 nonWhite = allWhite(lineList[i])
for i in range(len(lineList)): lineList[i] = lineList[i][nonWhite:]
#print "<pre>" #print "\n".join(lineList) tester = """ def _test(): import doctest doctest.testmod(verbose=True,optionflags=doctest.NORMALIZE_WHITESPACE) _test() """ exec "\n".join(lineList) + tester
#print "</pre>" ------------------------------------------------