Here's a solution using ba(s|tc)h.
To load a sujetset.sty file you can use texsrc sujetset or texsrc sujetset.sty. If you don't specify the extension (actually, if the file name you given was not found), the function tries cls, sty, and def, in this order. Upon not finding a file the function tries these fallback extensions, but this slows down the process due to extra calls to kpsewhich.
You can also pass a second argument, the function tries to use it as the editor, so texsrc article nano would open article.cls in nano.
Both versions are essentially the same code (modulo the batch version being a collage of code snippets from around the internet :-). The main difference is the choice of editor:
The bash version checks if $2 is given; if it is not, the default $EDITOR is used, otherwise it searches for the executable in $2 with which and issues an error if it doesn't exist. If no editor was given and $EDITOR is not set, another error is raised.
The batch version due to my lack of knowledge can't test if an executable exists, so it uses %EDITOR if defined, or uses %2if given, or uses notepad because. If anything is set wrong, chaos ensues :-)
Here's the bash version:
function texsrc {
if [ $# -eq "0" ]; then
echo 'Use texsrc <package name>'
return 1
fi
tryfile=$(kpsewhich "$1")
if [ -n "$tryfile" ]; then
filetoload=$tryfile
else
for i in cls sty def; do
tryfile=$(kpsewhich "$1.$i")
if [ -n "$tryfile" ]; then
filetoload=$tryfile
break
fi
done
fi
if [ -z "$filetoload" ]; then
echo "No file found."
return 1
fi
if [ $# -eq "2" ]; then
if [ -z $(which $2) ]; then
echo I couldn''t find the editor $2
else
texed=$2
fi
else
texed=$EDITOR
fi
if [ -n "$texed" ]; then
eval $texed $filetoload
else
echo I Couldn''t find an appropriate editor to open the file: $filetoload
fi
}
and a batch version:
@echo off
:texsrc
setlocal enabledelayedexpansion
if %1.==. goto ZeroArgs
call :SearchFile tryfile %1
if "%tryfile%"=="" (
for %%g in (cls,sty,def) do (
call :SearchFile tryfile "%1.%%g"
if defined tryfile (
set filetoload=!tryfile!
goto FileFound
)
)
) else (
set filetoload=%tryfile%
)
:FileFound
if "%filetoload%"=="" (
echo "No file found."
goto Return1
)
if defined EDITOR (set texed=%EDITOR%)
if not %2.==. (set texed=%2)
if not defined texed (set texed=notepad)
start "" %texed% %filetoload%
endlocal
exit /B 0
:SearchFile
setlocal
for /f "tokens=* usebackq" %%f in (`kpsewhich %2`) do (set _var=%%f)
endlocal & set %1=%_var%
exit /B 0
:ZeroArgs
echo Use texsrc ^<package name^>
goto Return1
:Return1
endlocal
exit /B 1
P.S.: Don't edit your TeX installation files directly :)
texsrc sujetset.styand it opens in the current$EDITOR. More or less liketexdoc, but way simpler. Would you be interested? – Phelype Oleinik Nov 16 '18 at 15:47bash, the need is not so great anyway: one can donano `kpsewhich sujetset.sty`or similar ... – Joseph Wright Nov 16 '18 at 15:50.styfiles (for very good reasons), maybe it would be a good idea to come up with a different system for your package that involves only changing files that were not installed by the system and that you can guarantee a user has the permissions to write anyway. – moewe Nov 16 '18 at 15:53styfile such commands:\def\@school{name-of-school}and\newcommand{\school}[1]{\gdef\@school{#1}}. Then, you use in your code the macro\@school. Now, user simply type in the maintexfile the following:\school{here it is}to change the value of\@school, which is in use in your style file. In this case, user does not need to edit style file. – Sigur Nov 16 '18 at 21:46\school{name-of-school}every time he need to create new document with this package, I think it is better for the user if it can change it insujetsetfile once . – Salim Bou Nov 17 '18 at 05:38\newcommandrather than\defso that users get meaningful errors in case of conflicts. There's no reason to use\defhere. – cfr Nov 18 '18 at 01:06graphixorbiblatexor whatever. You look for a file with a particular name. If it exists, you input it. If not, you carry on. Or you provide a default configuration file which users can copy if they like and modify. Then you input it unconditionally and you'll get the user's if it exists or your defaults otherwise. There's no need to require users to provide such a file. Make it optional. – cfr Nov 18 '18 at 22:19