function texeditor(varargin)
%TEXEDITOR TeX equation editor
% TEXEDITOR starts an equation editor for LaTeX equations.
%
% See also: TEXT, TEX
% Copyright 2006-2010 The MathWorks, Inc.
%todo:
% move templates around
% select text and see it highlighted in eqn preview
% shortcut window needs improvement
% say how to reset to default templates
figs = allchild(0);
f = findall(figs,'flat','Type','figure','Tag','TexEditorFigure');
if nargin > 0
callbacks = getappdata(f,'Callbacks');
feval(callbacks.cmdCB,varargin{:});
return;
end
if ~isempty(f)
set(f,'Visible','on');
figure(f);
return;
end
if ~usejava('swing')
error('texeditor:NeedSwing','Equation editor requires Java Swing.');
end
dirname = fullfile(tempdir, 'texeditor');
% make sure Java .class and other helper files are on the path
if ~exist(dirname,'dir') || isempty(which('TeXAction'))
extractFiles(tempdir);
javaaddpath(dirname);
addpath(dirname);
end
% make sure icons are on the path
back = get(0,'DefaultFigureColor');
set(f,'Color',back);
[addim,addcmap] = imread('move_down.gif');
addcmap(end,:) = back;
rolladdcmap = addcmap;
roll = back.*[.75 .75 1];
rolladdcmap(end,:) = roll;
[delim,delcmap] = imread('delete.gif');
delcmap(200:end,:) = repmat(back,size(delcmap,1)-199,1);
disdelcmap = delcmap;
disdelcmap(1:100,:) = repmat(back*.7,100,1);
rolldelcmap = delcmap;
rolldelcmap(200:end,:) = repmat(roll,size(delcmap,1)-199,1);
addbuth = []; % for callbacks
deletebuth = []; % for callbacks
f = figure('MenuBar','none','ToolBar','none',...
'Name','Equation Editor',...
'Tag','TexEditorFigure',...
'NumberTitle','off',...
'HandleVisibility','callback',...
'DeleteFcn',@deletecb,...
'ResizeFcn',@layoutcb,...
'Position',[0 0 450 350],...
'Visible','off');
% read preferences or create defaults if none
if ispref('texeditor','ActionTable')
actionTable = getpref('texeditor','ActionTable');
else
actionTable = { ...
% key, cmd
'/','\frac{}{}';...
'f','\frac{}{}';...
's','\sum_{}^{}';...
'p','\prod_{}^{}';...
'i','\int_{}^{}';...
'l','\lim_{ \to }';...
'q','\sqrt{}';...
'a','\alpha ';...
'b','\beta ';...
'g','\gamma ';...
'd','\delta ';...
'o','\overline{}';...
'u','\underline{}';...
't','\dot{}';...
'h','\hat{}'...
};
end
if ispref('texeditor','Templates')
templates = getpref('texeditor','Templates');
else
templates = {...
'\alpha x_1^2 + \beta x_2^2',...
'\sqrt{x+1}',...
'\lim_{n \to \infty} \frac{1}{1+n}',...
'\int_0^1 x \,dx',...
'\sum_{n=0}^{\infty} \frac{1}{n^2}',...
['\left[ \begin{array}{cc}' char(10) ' A\ & B \\' ...
char(10) ' C\ & D' char(10) '\end{array}\right]']...
};
end
% spacing in pixels
bgap = 6;
left = 107;
bottom = 40;
% template buttons
buttonHeight = 48;
buttonWidth = 80;
% gui buttons
guiBW = 65;
guiBH = 25;
% make Preview pane
ax=axes('Units','pixels',...
'XLim',[0 1],'YLim',[0 1],...
'Layer','top',...
'Parent',f,...
'XTick',[],'YTick',[],'Box','on');
defaultFontSize = 20;
dt = text(.5,.9,'','Interpreter','latex',...
'VerticalAlignment','top','HorizontalAlignment','center',...
'FontSize',defaultFontSize,'Parent',ax);
errt = text(.5,.1,'','Interpreter','none',...
'VerticalAlignment','bottom','HorizontalAlignment','center',...
'FontSize',12,'Parent',ax);
setappdata(f,'lastKnownGoodString','');
setappdata(f,'lastEditedString','');
% make Java text pane - undocumented feature alert!
jc = com.mathworks.mwswing.MJTextPane;
try
jfont = com.mathworks.hg.peer.FontConverter.convertToJavaFont('Courier',14,0,0);
catch
jfont = com.mathworks.hg.util.FontConverter.convertToJavaFont('Courier',14,0,0);
end
set(jc,'Font',jfont);
%[dummy,jch] = javacomponent(jc,[left+bgap .75 1-2*bgap-left .17].*pos,f);
[dummy,jch] = javacomponent(jc,[0 0 1 1],f);
jcc = handle(jc,'CallbackProperties');
set(jcc,'KeyTypedCallback',@typedCB)
set(jcc,'CaretUpdateCallback',@caretCB)
tabAct = TeXAction;
tabAct.putValue(javax.swing.Action.SHORT_DESCRIPTION,'Tab');
% hmm... this still will put a Tab character into the contents...
keymap = jc.getKeymap;
keymap.addActionForKeyStroke(...
javax.swing.KeyStroke.getKeyStroke('released TAB'),tabAct);
setappdata(f,'Callbacks',jcc); % needed?
%todo: margin in scrollpane
jbp = com.mathworks.mwswing.MJPanel(com.mathworks.page.utils.VertFlowLayout);
jsp = com.mathworks.mwswing.MJScrollPane(jbp,javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,...
javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
jsbar = jsp.getVerticalScrollBar;
set(jsp,'Font',jfont);
[dummy,jcompsp] = javacomponent(jsp,[0 0 1 1],f);
list = templates;
addbut = addIconButton('Add Template',addim,addcmap,...
@addtmplcb,[],rolladdcmap);
[dummy,addbuth] = javacomponent(addbut,[0 0 1 1],f);
deletebut = addIconButton('Delete Template',delim,delcmap,...
@deltmplcb,disdelcmap,rolldelcmap);
[dummy,deletebuth] = javacomponent(deletebut,[0 0 1 1],f);
setEnabled(deletebut,false);
miniax = axes('Units','pixels',...
'XLim',[0 1],'YLim',[0 1],...
'Layer','top','Visible','on',...
'Parent',f,...
'XTick',[],'YTick',[],'Box','off','Clipping','on',...
'XColor',back,'YColor',back);
defaultMiniFontSize = 10;
minit = text(.5,.5,'','Interpreter','latex',...
'VerticalAlignment','middle','HorizontalAlignment','center',...
'FontSize',defaultMiniFontSize,'Clipping','on',...
'HitTest','off','Parent',miniax);
set(miniax,'ButtonDownFcn',@lastbutcb);
set(f,'WindowButtonMotionFcn',@mousemovecb);
scutbut = uicontrol('style','pushbutton',...
'String','Shortcuts',...
'Parent',f,...
'Callback',@shortcutscb);
symsbut = uicontrol('style','pushbutton',...
'String','Symbols',...
'Parent',f,...
'Callback',@symbolscb);
helpbut = uicontrol('style','pushbutton',...
'String','Help',...
'Parent',f,...
'Callback',@helpcb);
closebut = uicontrol('style','pushbutton',...
'String','Close',...
'Parent',f,...
'Callback',@closecb);
movegui(f,'center');
set(f,'visible','on')
tim = timer('timerfcn',@dotimer,'startdelay',1,'executionmode','singleshot');
setappdata(f,'Callbacks',struct('cmdCB',@cmdCB));
doLayout;
drawnow;
pause(.5);
for k=length(list):-1:1
addTemplate(jbp,list{k},[]);
end
jc.requestFocus;
function doLayout
pos = get(f,'Position');
origpos = pos;
if pos(3) < 120
pos
温柔-的-女汉子
- 粉丝: 1089
- 资源: 4084
最新资源
- ORACLE数据库管理系统体系结构中文WORD版最新版本
- Sybase数据库安装以及新建数据库中文WORD版最新版本
- tomcat6.0配置oracle数据库连接池中文WORD版最新版本
- hibernate连接oracle数据库中文WORD版最新版本
- MyEclipse连接MySQL的方法中文WORD版最新版本
- MyEclipse中配置Hibernate连接Oracle中文WORD版最新版本
- MyEclipseTomcatMySQL的环境搭建中文WORD版3.37MB最新版本
- hggm - 国密算法 SM2 SM3 SM4 SM9 ZUC Python实现完整代码-算法实现资源
- SQLITE操作入门中文WORD版最新版本
- Sqlite操作实例中文WORD版最新版本
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈