On 09/22/2017 04:06 PM, Craig Markwardt wrote:
> On Thursday, September 21, 2017 at 7:10:52 AM UTC-4, Markus Schmassmann wrote:
>> I'm putting graphics created with the IDL graphics functions into a
>> LaTeX document.
>>
>> Does someone here know a way to make sure that the text elements of the
>> graphic (axis labels,axis tickmarks,titles,legends...) are typeset by
>> LaTeX such that they have the same fonts & sizes as the rest of the
>> LaTeX document?
>>
>> I'm looking for something similar to GNUplot's epslatex terminal.
>>
>> A brute force approach would be:
>>
>> idl -e "(plot(/test)).save,'example.eps'&exit"
>> grep '^(.*)$' -A 1 example.eps
>>
>> ; remove those lines from the eps file and parse them to get what I want
>> in LaTeX
>>
>> But I hope someone of you has a better way than to grep & sed an eps file.
> There used to be a package called psfrag which allowed one to do
> this. I haven't used it in something like two decades, but it sounds like
> what you want.
Hi Craig,
Thanks, this helped, although I have not yet figured out how to
automatically remove all the escapes of the labels in the eps file and
how to get the alignment of the new labels correctly.
But given that IDL doesn't get the label alignment right in eps I doubt
there is an automatic way to correct that in post processing.
For anyone who wants to try to fix this, or to use it despite it's
shortcomings, below is the procedure PSFRAG_PREP, which takes
<filename>.eps, outputs <filename>_tagNum.eps in which all labels have
been replaced by label# as well as <filename>.tex which contains the
\psfrac commands to replace the labels.
Markus
pro psfrag_prep, filename,example=example,verbose=verbose
; +
; PSFRAG_PREP:
; INPUT: FILENAME: <filename>.eps file to be processed
; OUTPUT: none in idl
; CREATES FILES: <filename>_tagNum.eps, labels replaced by 'label#'
; <filename>.tex, \psfrag commands
; may have to be edited manually
; KEYWORDS: EXAMPLE: creates an example file
; VERBOSE: prints the edited lines
; WARNING: eps file escapes area not delt with, must be edited out
; e.g. \psfrag{label1}{title $\sin\(2\pi x/25\)\exp\(-x/100\)$}
; --> \psfrag{label1}{title $\sin (2\pi x/25 )\exp (-x/100 )$}
; allignment may be problematic
;
; ~~~~~ MWE for LaTeX ~~~~~
; \documentclass{article}
; \usepackage{graphicx,psfrag}
; \begin{document}
; blablabla
; \begin{figure}
; \centering
; \include{example}
; \includegraphics[width=\linewidth]{example_tagNum}
; \caption{blublabla}
; \label{fig:ex}
; \end{figure}
; \end{document}
; ~~~~~ to be compiled by LaTeX,dvi2ps,ps2pdf ~~~~~
; -
if ~isa(filename,/string) then begin
filename='example'
example=!true
endif
if keyword_set(example) then (plot(/test,xtitle='x', $
title='title \$\sin(2\pi x/25)\exp(-x/100)\$')).save,filename+'.eps'
cmd= !version.os_family eq 'unix' ? 'wc -l '+filename+'.eps' : $
'findstr /r /n "^" '+filename+'.eps | find /c ":"'
spawn, cmd, out &
nLines=long(stregex(out[0],'[0-9]*',/extract))
lines=strarr(nLines)
openr, lun, filename+'.eps', /get_lun
readf, lun, lines
free_lun, lun
w=where(stregex(lines, '^\(.*\)$', /boolean),cnt)
tagLines=lines[w]
lines[w]='(label'+string(indgen(cnt)+1,format='(i0)')+')'
openw, lun, filename+'_tagNum.eps',/get_lun
printf, lun, lines, format='(a)'
free_lun,lun
noPadDollar=stregex(tagLines,'\([a-zA-Z\ ]*\)',/boolean) or $
strpos(tagLines,'$') ne -1
tex=strarr(cnt)
for i=0,cnt-1 do begin
tag=strmid(tagLines[i],1,strlen(tagLines[i])-2)
tex[i]='\psfrag{label'+string(i+1,format='(i0)')+'}{' + $
( noPadDollar[i] ? '' : '$' ) + tag + $
( noPadDollar[i] ? '' : '$' ) + '}'
endfor
openw, lun, filename+'.tex'
printf, lun, tex, format='(a)'
free_lun, lun
if keyword_set(verbose) then for i=0,cnt-1 do print, $
tagLines[i], lines[w[i]], tex[i],'',format='(a)'
if keyword_set(example) then print, 'PSFRAG_PREP, WARNING:', $
'eps file escapes area not delt with, must be edited out manually', $
' e.g. \psfrag{label1}{title $\sin\(2\pi x/25\)\exp\(-x/100\)$}', $
' --> \psfrag{label1}{title $\sin (2\pi x/25 )\exp (-x/100 )$}'
end
|