Advertisement
Guest User

Untitled

a guest
Jul 1st, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. latex -----------------> lua first call
  2. <-------- return full file name "/home/me/etc..../file_name.m"
  3.  
  4.  
  5.  
  6. (full file name)
  7. latex -------------------> second lua call
  8. <---- return final result
  9.  
  10. documentclass{article}
  11. IfFileExists{luatex85.sty}{usepackage{luatex85}}{}
  12.  
  13. ifdefinedHCode% detect tex4ht
  14. usepackage[utf8]{luainputenc}
  15. usepackage[T1]{fontenc}
  16. else
  17. usepackage{fontspec}
  18. fi
  19. usepackage{luacode}
  20.  
  21. begin{luacode*}
  22. require 'lfs'
  23. -- first LUA function
  24. function fullpath(curDir,fileName)
  25. local pathseparator = package.config:sub(1,1)
  26.  
  27. if os.type == "windows" then
  28. fileName=string.gsub(fileName,"/",pathseparator)
  29. end
  30.  
  31. local name=table.concat({lfs.currentdir(),fileName}, pathseparator);
  32. print(name)
  33. tex.print(name)
  34. end
  35.  
  36. -- second LUA function
  37. function format(fileName)
  38. --for now, just print it.
  39. tex.print("\verb|"..fileName.."|")
  40. end
  41. end{luacode*}
  42.  
  43. newcommandfullpath[2]{luadirect{fullpath(luastring,#2)}}
  44. newcommandformat[1]{luadirect{format(#1)}}
  45.  
  46. begin{document}
  47. %ask LUA to find full path name of some file. This should work
  48. %on both windows and Linux
  49.  
  50. %how to save this result in Latex?
  51. %fullpath{jobname.tex}{"sub_folder/foo7_1.tex"} %causes an error.
  52.  
  53. %edef causes error
  54. defname{fullpath{jobname.tex}{"sub_folder/foo7_1.tex"}}
  55.  
  56. %send the name back to lua. causes error if uncomment
  57. %format{name}
  58. end{document}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement