Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Is there a simple way to open ".sty" files by something similar to the "texdoc"? I'm looking for something like texsty to simply open .sty files.

share|improve this question
1  
Usually texdoc foo.sty works. If you're on a bash shell, also less $(kpsewhich foo.sty) does the same. –  egreg Jan 20 '13 at 21:49
3  
@VahidDamanafshan if you are using bash, just replace less in @egreg's suggestion with emacs or whatever editor you use and perhaps add a & at the end. –  David Carlisle Jan 20 '13 at 21:59
2  
@VahidDamanafshan What's your default latex editor? What's your OS? In my default editor (TeXShop) there's a menu item "Open .sty file" which does that. So we need more information. –  Alan Munn Jan 20 '13 at 22:04
1  
@VahidDamanafshan a shell is a command line interpreter in unix/linux operating systems. As you later said you are using windows you probably are using the standard windows cmd command line rather than bash so the $... syntax egreg suggested won't work. (I use bash as my command line on windows but this is by choice, it's not likely to happen by accident:-) –  David Carlisle Jan 20 '13 at 22:42
1  
@Sigur The texless trick works for (almost) any file in the TeX distribution. –  egreg Jul 18 '13 at 23:33
show 8 more comments

2 Answers

up vote 6 down vote accepted

Windows (without cyg)

Native Windows isn't really cut out for this. It's been a while since I did any batch file scripting, but try this:

Save the following as file texsty.bat and place it on your PATH (or in the working directory of your command prompt):

@echo off
for /f "usebackq tokens=*" %%a in (`kpsewhich %*.sty`) do "C:\Program Files\Texmaker\texmaker" "%%a"

Use as eg texsty hyperref. If you want to be able to specify files which do not end in .sty (eg .cls, .pdf, .dtx, .clo) then you can remove the .sty extension from just after the %* in the batch file, but then would have to invoke for sty files as eg texsty hyperref.sty (and it might be better to call it texstart instead of texsty in that case).

This assumes that Texmaker is installed in the default path. For other editors/paths, one can edit the command line accordingly. It should also be possible to use start to use the default program associated with sty files, but this doesn't work for me via this batch file...

I got the syntax from Batch equivalent of Bash backticks.

Bash (or similar shells)

For completeness, if using bash, I would add the following function definition to my ~/.bashrc file:

texsty ()
{
# invoke kpsewhich, but remove any unwanted characters that may show up on Windows
local kpseret="$(kpsewhich "$1.sty" | tr -d '\r')"
if [ -z "$kpseret" ]; then
echo "'$1' not found."
else
xdg-open "$kpseret"
#or for Windows, use start instead of xdg-open:
#start "$kpseret"
fi
}

This just wraps the method offered by egreg in his comment into a more convenient function. Again, invoke as eg texsty hyperref. Personally, I'd probably prefer the more general texstart obtained by removing .sty from the kpsewhich call and renaming the function, then invoke as eg texstart hyperref.sty.

share|improve this answer
    
Thank, but how to "append it to the %* in the batch file."? –  Vahid Damanafshan Jan 21 '13 at 9:43
    
@VahidDamanafshan: I have reversed the answer so that the .sty extension is now there by default, and I have explained how to remove it instead of how to add it. –  cyberSingularity Jan 21 '13 at 10:55
add comment

Unfortunately windows does not have the flexibility of unix commands. This has to be done on two step process or using a script as per the accepted answer.

You use kpsewhich filename.sty to locate and then you type the path and the editor name in my case notepad. If you doinf this thing often download sublime2 and have it on the path.

enter image description here

EDLIN.EXE not supported anymore! However EDIT still works and you can replace Notepad with EDIT if you like.

This answer is more of a note to myself.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.