Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with "relativeDataPath" option [Windows only] #1105

Open
kentgens opened this issue Jan 14, 2022 · 2 comments
Open

Issue with "relativeDataPath" option [Windows only] #1105

kentgens opened this issue Jan 14, 2022 · 2 comments

Comments

@kentgens
Copy link

My matlab2tikz workflow heavily involves sneaking in Tex macros into matlab2tikz arguments such as 'width', 'height', 'extraAxisOptions', 'relativeDataPath' to control the figure appearance from within my Latex document.

However, I am facing a problem with relativeDataPath. I would like to set this option to \figuredatadir, which is a macro set by my Latex main document. This works well under Linux, but is a problem now as I am switching to Windows. The problem is that under Windows, the backslash \ will be replaced by a forward slash /.

The responsible line is in the internal function TeXpath:

path = strrep(path, filesep, '/');

Currently, I am helping me out with a quite dirty hack by having a function strrep in my workspace which overrides MATLAB's builtin strrep function to avoid patching my copy of matlab2tikz:

% THIS IS A HACK FOR MATLAB2TIKZ
%
% When setting 'relativeDataPath' as a matlab2tikz option, the following
% function comes into play:
%
%     function path = TeXpath(path)
%         path = strrep(path, filesep, '/');
%         % TeX uses '/' as a file separator (as UNIX). Windows, however, uses
%         % '\' which is not supported by TeX as a file separator
%     end
%
% This function prevents to have the Tex command '\figuredatadir' replaced in
% 'relativeDataPath' when runnning under Windows. For Linux or Mac OS, this
% hack is not necessary.
function varargout = strrep(varargin)
    
    [varargout{1:nargout}] = builtin('strrep',varargin{:});
    
    % Different behavior if caller function is "TeXpath" in file "matlab2tikz.m"
    curStack = dbstack();
    if length(curStack)>1 && strcmp(curStack(2).file,'matlab2tikz.m') && strcmp(curStack(2).name,'TeXpath')
        varargout{1} = strrep(varargout{1},'/figuredatadir','\figuredatadir');
    end
end

I am not even sure if the mentioned behavior can be called a bug. If not, I would like to know if there is any better or even recommended way to sneak in Latex commands into relativeDataPath? You may also put this a feature request.

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
@kentgens and others